Pro.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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')->where('is_removed', false);
  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. public function currentWork() {
  69. return ProClientWork::where('pro_id', $this->id)->where('is_active', true)->first();
  70. }
  71. public function isWorkingOnClient($_client) {
  72. $count = ProClientWork::where('pro_id', $this->id)->where('client_id', $_client->id)->where('is_active', true)->count();
  73. return $count > 0;
  74. }
  75. public function canvasCustomItems($_key) {
  76. return ClientCanvasDataCustomItem::where('key', $_key)->get();
  77. }
  78. }