Pro.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 initials() {
  20. $characters = [];
  21. if(!empty($this->name_first)) $characters[] = $this->name_first[0];
  22. if(!empty($this->name_last)) $characters[] = $this->name_last[0];
  23. return strtoupper(implode("", $characters));
  24. }
  25. public function cmBills()
  26. {
  27. return $this->hasMany(Bill::class, 'cm_pro_id');
  28. }
  29. public function hcpBills()
  30. {
  31. return $this->hasMany(Bill::class, 'hcp_pro_id');
  32. }
  33. public function lastPayment() {
  34. return ProTransaction
  35. ::where('pro_id', $this->id)
  36. ->where('plus_or_minus', 'PLUS')
  37. ->orderBy('created_at', 'desc')
  38. ->first();
  39. }
  40. public function hasRates() {
  41. $numRates = ProRate::where('is_active', true)->where('pro_id', $this->id)->count();
  42. return $numRates > 0;
  43. }
  44. public function cmRates() {
  45. return ProRate::distinct('code')
  46. ->where('is_active', true)
  47. ->where('pro_id', $this->id)
  48. ->where('code', 'LIKE', 'CM%')
  49. ->get();
  50. }
  51. public function rmRates() {
  52. return ProRate::distinct('code')
  53. ->where('is_active', true)
  54. ->where('pro_id', $this->id)
  55. ->where('code', 'LIKE', 'RM%')
  56. ->get();
  57. }
  58. public function noteRates() {
  59. return ProRate::distinct('code')
  60. ->where('is_active', true)
  61. ->where('pro_id', $this->id)
  62. ->where('code', 'NOT LIKE', 'CM%')
  63. ->where('code', 'NOT LIKE', 'RM%')
  64. ->get();
  65. }
  66. public function shortcuts() {
  67. return $this->hasMany(ProTextShortcut::class, 'pro_id')->where('is_removed', false);
  68. }
  69. public function noteTemplates() {
  70. return $this->hasMany(NoteTemplatePro::class, 'pro_id')
  71. ->where('is_removed', false)
  72. ->orderBy('position_index', 'asc');
  73. }
  74. public function currentWork() {
  75. return ProClientWork::where('pro_id', $this->id)->where('is_active', true)->first();
  76. }
  77. public function isWorkingOnClient($_client) {
  78. $count = ProClientWork::where('pro_id', $this->id)->where('client_id', $_client->id)->where('is_active', true)->count();
  79. return $count > 0;
  80. }
  81. public function canvasCustomItems($_key) {
  82. return ClientCanvasDataCustomItem::where('key', $_key)->get();
  83. }
  84. }