CareMonth.php 898 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Models;
  3. # use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Collection;
  5. class CareMonth extends Model
  6. {
  7. protected $table = 'care_month';
  8. public function patient(){
  9. return $this->hasOne(Client::class, 'id', 'client_id');
  10. }
  11. public function mcp(){
  12. return $this->hasOne(Pro::class, 'id', 'mcp_pro_id');
  13. }
  14. public function entries() {
  15. return $this->hasMany(CareMonthEntry::class, 'care_month_id', 'id');
  16. }
  17. public function bills() {
  18. return $this->hasMany(Bill::class, 'care_month_id', 'id');
  19. }
  20. public function getBillsOfType($_type) {
  21. $bills = $this->bills;
  22. $targetBills = new Collection();
  23. foreach ($bills as $bill) {
  24. if($bill->cm_or_rm === $_type) {
  25. $targetBills->add($bill);
  26. }
  27. }
  28. return $targetBills;
  29. }
  30. }