All checks were successful
Build project image / Build-and-release-image (push) Successful in 3m9s
92 lines
2.0 KiB
PHP
92 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Project extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'customer_id',
|
|
'name',
|
|
'project_number',
|
|
'description',
|
|
'start_date',
|
|
'end_date',
|
|
];
|
|
|
|
/**
|
|
* The attributes that are appended with attribute getters.
|
|
*
|
|
* @var string[]
|
|
*/
|
|
protected $appends = [
|
|
'start',
|
|
'end',
|
|
'customer_email',
|
|
'customer_name',
|
|
'next_invoice_count',
|
|
];
|
|
|
|
|
|
public function getCustomerNameAttribute(): string
|
|
{
|
|
return $this->customer->name;
|
|
}
|
|
public function getCustomerEmailAttribute(): string
|
|
{
|
|
return $this->customer->email;
|
|
}
|
|
|
|
/**
|
|
* Get the end_date attribute in local format.
|
|
*/
|
|
public function getStartAttribute(): string
|
|
{
|
|
return (is_null($this->start_date)) ? '' : Carbon::createFromFormat('Y-m-d', $this->start_date)->format('d.m.Y');
|
|
}
|
|
|
|
/**
|
|
* Get the next invoice number for this project.
|
|
*/
|
|
public function getNextInvoiceCountAttribute(): int
|
|
{
|
|
return $this->invoices()->max('project_count') + 1 ?? 1;
|
|
}
|
|
|
|
/**
|
|
* Get the end_date attribute in local format.
|
|
*/
|
|
public function getEndAttribute(): string
|
|
{
|
|
return (is_null($this->end_date)) ? '' : Carbon::createFromFormat('Y-m-d', $this->end_date)->format('d.m.Y');
|
|
}
|
|
|
|
/**
|
|
* Get the customer this project belongs to.
|
|
*/
|
|
public function customer(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Customer::class)->withTrashed();
|
|
}
|
|
|
|
/**
|
|
* Get the invoices for this project.
|
|
*/
|
|
public function invoices(): HasMany
|
|
{
|
|
return $this->hasMany(Invoice::class);
|
|
}
|
|
}
|