Add contract management and invoice settings pages
- Created a new Blade view for managing brand contracts with forms for adding and editing contracts, including client and category selection. - Implemented success message notifications for contract actions. - Added a new Blade view for invoice settings, allowing customization of invoice number format, header branding, and default values for new invoices. - Introduced a new PDF view for generating rate cards with customizable styles based on user profile settings. - Developed a profile management page for rate cards, enabling users to update their identity, appearance, and visibility settings.
This commit is contained in:
75
app/Models/BrandContract.php
Normal file
75
app/Models/BrandContract.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class BrandContract extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'title', 'client_id', 'category_id',
|
||||
'start_date', 'end_date', 'notes', 'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
// ── Relationships ────────────────────────────────────────────
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class);
|
||||
}
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ClientCategory::class, 'category_id');
|
||||
}
|
||||
|
||||
// ── Scopes ───────────────────────────────────────────────────
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true)
|
||||
->where('start_date', '<=', today())
|
||||
->where('end_date', '>=', today());
|
||||
}
|
||||
|
||||
// ── Helpers ──────────────────────────────────────────────────
|
||||
|
||||
public function isCurrentlyActive(): bool
|
||||
{
|
||||
return $this->is_active
|
||||
&& $this->start_date->lte(today())
|
||||
&& $this->end_date->gte(today());
|
||||
}
|
||||
|
||||
public function getDaysRemainingAttribute(): int
|
||||
{
|
||||
return (int) max(0, today()->diffInDays($this->end_date, false));
|
||||
}
|
||||
|
||||
public function getStatusLabelAttribute(): string
|
||||
{
|
||||
if (! $this->is_active) return 'Inactive';
|
||||
if ($this->start_date->gt(today())) return 'Upcoming';
|
||||
if ($this->end_date->lt(today())) return 'Expired';
|
||||
return 'Active';
|
||||
}
|
||||
|
||||
public function getStatusColorAttribute(): string
|
||||
{
|
||||
return match ($this->statusLabel) {
|
||||
'Active' => 'badge-success',
|
||||
'Upcoming' => 'badge-info',
|
||||
'Expired' => 'badge-neutral',
|
||||
default => 'badge-ghost',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user