Client.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Relations\HasOne;
  4. # use Illuminate\Database\Eloquent\Model;
  5. class Client extends Model
  6. {
  7. protected $table = 'client';
  8. public function displayName() {
  9. return $this->name_last . ', '. $this->name_first;
  10. }
  11. public function mcp() {
  12. return $this->hasOne(Pro::class, 'id', 'mcp_pro_id');
  13. }
  14. public function cm() {
  15. return $this->hasOne(Pro::class, 'id', 'cm_pro_id');
  16. }
  17. public function rmm() {
  18. return $this->hasOne(Pro::class, 'id', 'rmm_pro_id');
  19. }
  20. public function prosInMeetingWith() {
  21. return Pro::where('in_meeting_with_client_id', $this->id)->get();
  22. }
  23. public function notes() {
  24. return $this->hasMany(Note::class, 'client_id', 'id')->orderBy('created_at', 'desc');
  25. }
  26. public function duplicateOf() {
  27. return $this->hasOne(Client::class, 'id', 'duplicate_of_client_id');
  28. }
  29. public function actionItems () {
  30. return $this->hasMany(ActionItem::class, 'client_id', 'id')
  31. ->orderBy('action_item_category', 'asc')
  32. ->orderBy('created_at', 'desc');
  33. }
  34. public function infoLines() {
  35. return $this->hasMany(ClientInfoLine::class, 'client_id', 'id')->orderBy('created_at', 'desc');
  36. }
  37. public function measurements() {
  38. return $this->hasMany(Measurement::class, 'client_id', 'id')
  39. ->distinct('label')
  40. ->where('is_removed', false)
  41. ->orderBy('label', 'asc')
  42. ->orderBy('effective_date', 'desc');
  43. }
  44. public function smses() {
  45. return $this->hasMany(ClientSMS::class, 'client_id', 'id')
  46. ->orderBy('created_at', 'desc');
  47. }
  48. public function documents() {
  49. return $this->hasMany(ClientDocument::class, 'client_id', 'id')
  50. ->orderBy('created_at', 'desc');
  51. }
  52. public function smsNumbers() {
  53. return $this->hasMany(ClientSMSNumber::class, 'client_id', 'id')
  54. ->orderBy('created_at', 'desc');
  55. }
  56. public function nextMcpAppointment() {
  57. if($this->mcp) {
  58. return Appointment::where('client_id', $this->id)
  59. ->where('pro_id', $this->mcp->id)
  60. ->where('start_time', '>=', date('Y-m-d'))
  61. ->orderBy('start_time', 'asc')
  62. ->first();
  63. }
  64. return false;
  65. }
  66. public function appointments() {
  67. return $this->hasMany(Appointment::class, 'client_id', 'id')
  68. ->orderBy('start_time', 'desc');
  69. }
  70. public function memos() {
  71. return $this->hasMany(ClientMemo::class, 'client_id', 'id')
  72. ->where('is_cancelled', false)
  73. ->orderBy('created_at', 'desc');
  74. }
  75. public function devices() {
  76. return $this->hasMany(ClientBDTDevice::class, 'client_id', 'id')
  77. ->where('is_active', true)
  78. ->orderBy('created_at', 'desc');
  79. }
  80. public function deviceMeasurements() {
  81. return $this->hasMany(ClientBDTMeasurement::class, 'client_id', 'id')
  82. ->orderBy('created_at', 'desc');
  83. }
  84. }