<commit_before><?php

namespace App;

use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;

class Vacancy extends Model
{
    protected $fillable = ['business_id', 'service_id', 'date', 'start_at', 'finish_at', 'capacity'];

    protected $guarded = ['id'];

    protected $dates = ['start_at', 'finish_at'];

    public function business()
    {
        return $this->belongsTo('App\Business');
    }

    public function service()
    {
        return $this->belongsTo('App\Service');
    }

    public function scopeForDate($query, Carbon $date)
    {
        return $query->where('date', '=', $date->toDateString());
    }

    public function scopeFuture($query)
    {
        return $query->where('date', '>', Carbon::now());
    }

    public function scopeForService($query, Service $service)
    {
        return $query->where('service_id', '=', $service->id);
    }

    public function isFull(Collection $appointments)
    {
        $slots = $this->capacity;
        foreach ($appointments as $appointment) {
            if ($this->holdsAppointment($appointment)) {
                $slots--;
            }
        }
        return $slots < 1;
    }

    public function holdsAppointment(Appointment $appointment)
    {
        return (($this->date == $appointment->date) &&
               ($this->service_id == $appointment->service_id) &&
               ($this->business_id == $appointment->business_id));
    }

    public function holdsAnyAppointment(Collection $appointments)
    {
        foreach ($appointments as $appointment) {
            if ($this->holdsAppointment($appointment)) return true;
        }
        return false;
    }
}<commit_msg>Bugfix: Make Appointments discount Vacancy capacity only if active<commit_after><?php

namespace App;

use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;

class Vacancy extends Model
{
    protected $fillable = ['business_id', 'service_id', 'date', 'start_at', 'finish_at', 'capacity'];

    protected $guarded = ['id'];

    protected $dates = ['start_at', 'finish_at'];

    public function business()
    {
        return $this->belongsTo('App\Business');
    }

    public function service()
    {
        return $this->belongsTo('App\Service');
    }

    public function scopeForDate($query, Carbon $date)
    {
        return $query->where('date', '=', $date->toDateString());
    }

    public function scopeFuture($query)
    {
        return $query->where('date', '>', Carbon::now());
    }

    public function scopeForService($query, Service $service)
    {
        return $query->where('service_id', '=', $service->id);
    }

    public function isFull(Collection $appointments)
    {
        $slots = $this->capacity;
        foreach ($appointments as $appointment) {
            if ($this->holdsAppointment($appointment)) {
                $slots--;
            }
        }
        return $slots < 1;
    }

    public function holdsAppointment(Appointment $appointment)
    {
        return ($appointment->isActive() &&
                ($this->date == $appointment->date) &&
                ($this->service_id == $appointment->service_id) &&
                ($this->business_id == $appointment->business_id)
               );
    }

    public function holdsAnyAppointment(Collection $appointments)
    {
        foreach ($appointments as $appointment) {
            if ($this->holdsAppointment($appointment)) return true;
        }
        return false;
    }
}
{'fraction_non_alphanumeric': 0.1433833947293851, 'fraction_numerical': 0.0005667327854916407, 'mean_word_length': 2.5801217038539552, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4843609', 'n_tokens_mistral': 1033, 'n_tokens_neox': 1004, 'n_words': 211}