'object', 'line_items' => 'object', ]; protected $appends = [ 'hashed_id', 'status' ]; public function company() { return $this->belongsTo(Company::class); } public function client() { return $this->belongsTo(Client::class); } public function user() { return $this->belongsTo(User::class); } public function invitations() { $this->morphMany(RecurringInvoiceInvitation::class); } public function getStatusAttribute() { if($this->status_id == RecurringInvoice::STATUS_ACTIVE && $this->start_date > Carbon::now()) //marked as active, but yet to fire first cycle return RecurringInvoice::STATUS_PENDING; else if($this->status_id == RecurringInvoice::STATUS_ACTIVE && $this->next_send_date > Carbon::now()) return RecurringInvoice::STATUS_COMPLETED; else return $this->status_id; } public function nextSendDate() :?Carbon { switch ($this->frequency_id) { case RecurringInvoice::FREQUENCY_WEEKLY: return Carbon::parse($this->next_send_date->addWeek()); case RecurringInvoice::FREQUENCY_TWO_WEEKS: return Carbon::parse($this->next_send_date->addWeeks(2)); case RecurringInvoice::FREQUENCY_FOUR_WEEKS: return Carbon::parse($this->next_send_date->addWeeks(4)); case RecurringInvoice::FREQUENCY_MONTHLY: return Carbon::parse($this->next_send_date->addMonth()); case RecurringInvoice::FREQUENCY_TWO_MONTHS: return Carbon::parse($this->next_send_date->addMonths(2)); case RecurringInvoice::FREQUENCY_THREE_MONTHS: return Carbon::parse($this->next_send_date->addMonths(3)); case RecurringInvoice::FREQUENCY_FOUR_MONTHS: return Carbon::parse($this->next_send_date->addMonths(4)); case RecurringInvoice::FREQUENCY_SIX_MONTHS: return Carbon::parse($this->next_send_date->addMonths(6)); case RecurringInvoice::FREQUENCY_ANNUALLY: return Carbon::parse($this->next_send_date->addYear()); case RecurringInvoice::FREQUENCY_TWO_YEARS: return Carbon::parse($this->next_send_date->addYears(2)); default: return null; } } public function remainingCycles() : int { if($this->remaining_cycles == 0) return 0; else return $this->remaining_cycles - 1; } public function setCompleted() : void { $this->status_id = self::STATUS_COMPLETED; $this->next_send_date = null; $this->remaining_cycles = 0; $this->save(); } public static function badgeForStatus(int $status) { switch ($status) { case RecurringInvoice::STATUS_DRAFT: return '