Pro.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. public function cmRates() {
  39. return ProRate::distinct('code')
  40. ->where('is_active', true)
  41. ->where('pro_id', $this->id)
  42. ->where('code', 'LIKE', 'CM%')
  43. ->get();
  44. }
  45. public function rmRates() {
  46. return ProRate::distinct('code')
  47. ->where('is_active', true)
  48. ->where('pro_id', $this->id)
  49. ->where('code', 'LIKE', 'RM%')
  50. ->get();
  51. }
  52. public function noteRates() {
  53. return ProRate::distinct('code')
  54. ->where('is_active', true)
  55. ->where('pro_id', $this->id)
  56. ->where('code', 'NOT LIKE', 'CM%')
  57. ->where('code', 'NOT LIKE', 'RM%')
  58. ->get();
  59. }
  60. public function shortcuts() {
  61. return $this->hasMany(ProTextShortcut::class, 'pro_id');
  62. }
  63. public function noteTemplates() {
  64. return $this->hasMany(NoteTemplatePro::class, 'pro_id')
  65. ->where('is_removed', false)
  66. ->orderBy('position_index', 'asc');
  67. }
  68. }