Premier commit

This commit is contained in:
jeremy bayse
2026-02-09 11:27:21 +01:00
commit 89a369964d
114 changed files with 17837 additions and 0 deletions

23
app/Models/AuditLog.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class AuditLog extends Model
{
use HasFactory;
protected $guarded = ['id'];
protected $casts = [
'changes' => 'array',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

60
app/Models/Contract.php Normal file
View File

@@ -0,0 +1,60 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Contract extends Model
{
use HasFactory;
protected $fillable = [
'name',
'reference',
'provider',
'status',
'start_date',
'end_date',
'amount',
'currency',
'notes',
'type',
'municipality_id',
];
protected $casts = [
'start_date' => 'date',
'end_date' => 'date',
'amount' => 'decimal:2',
];
public function meta(): HasMany
{
return $this->hasMany(ContractMeta::class);
}
public function documents(): HasMany
{
return $this->hasMany(Document::class);
}
public function municipality(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Municipality::class);
}
// Helpers
public function scopeActive($query)
{
return $query->where('status', 'active');
}
public function scopeExpiringSoon($query, $days = 30)
{
return $query->where('end_date', '<=', now()->addDays($days))
->where('end_date', '>=', now())
->where('status', '!=', 'expired');
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ContractMeta extends Model
{
use HasFactory;
protected $table = 'contract_meta'; // singular/plural convention can be tricky if not explicit
protected $fillable = [
'contract_id',
'key',
'value',
];
public function contract(): BelongsTo
{
return $this->belongsTo(Contract::class);
}
}

32
app/Models/Document.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Document extends Model
{
use HasFactory;
protected $fillable = [
'contract_id',
'filename',
'path',
'mime_type',
'size',
'description',
'uploaded_by',
];
public function contract(): BelongsTo
{
return $this->belongsTo(Contract::class);
}
public function uploader(): BelongsTo
{
return $this->belongsTo(User::class, 'uploaded_by');
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class GlobalSetting extends Model
{
protected $fillable = ['key', 'value'];
/**
* Get a global setting value by key.
*/
public static function get(string $key, $default = null)
{
$setting = self::where('key', $key)->first();
return $setting ? $setting->value : $default;
}
/**
* Set a global setting value.
*/
public static function set(string $key, $value)
{
return self::updateOrCreate(
['key' => $key],
['value' => $value]
);
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class LicenseLevel extends Model
{
protected $fillable = ['name', 'type', 'is_active'];
public function scopeActive($query)
{
return $query->where('is_active', true);
}
}

22
app/Models/Link.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Link extends Model
{
use HasFactory;
protected $fillable = ['title', 'url', 'icon', 'color', 'order', 'is_active'];
protected $casts = [
'is_active' => 'boolean',
];
public function scopeActive($query)
{
return $query->where('is_active', true)->orderBy('order', 'asc');
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Municipality extends Model
{
protected $fillable = ['name', 'zip_code', 'is_active'];
public function scopeActive($query)
{
return $query->where('is_active', true);
}
public function contracts()
{
return $this->hasMany(Contract::class);
}
}

66
app/Models/User.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
'role',
'is_active',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'is_active' => 'boolean',
];
}
public function isAdmin(): bool
{
return $this->role === 'admin';
}
public function isManager(): bool
{
return $this->role === 'manager' || $this->isAdmin();
}
public function scopeActive($query)
{
return $query->where('is_active', true);
}
}