mejoras en la gestión de proyectos y documentos: se añaden nuevos campos y validaciones para optimizar la organización y el seguimiento de los mismos.
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled

This commit is contained in:
2025-10-25 11:29:20 +02:00
parent 28c225687a
commit d8ae8c8894
29 changed files with 2054 additions and 856 deletions

65
app/Models/Company.php Normal file
View File

@@ -0,0 +1,65 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Company extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = [
'name',
'commercial_name',
'status',
'address',
'postal_code',
'city',
'country',
'phone',
'email',
'cif',
'logo'
];
protected $casts = [
'created_at' => 'datetime:d/m/Y H:i',
'updated_at' => 'datetime:d/m/Y H:i',
];
public function getStatusColorAttribute()
{
return [
'active' => 'bg-green-100 text-green-800',
'closed' => 'bg-red-100 text-red-800',
][$this->status] ?? 'bg-gray-100 text-gray-800';
}
public function getStatusTextAttribute()
{
return [
'active' => 'Activo',
'closed' => 'Cerrado',
][$this->status] ?? 'Desconocido';
}
public function contacts(): BelongsToMany
{
return $this->belongsToMany(User::class, 'company_contacts')
->withPivot('position')
->withTimestamps();
}
public function users()
{
return $this->hasMany(User::class);
}
public function projects()
{
return $this->hasMany(Project::class);
}
}

View File

@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
protected $fillable = [
'reference',
'name',
'description',
'creator_id',
@@ -22,6 +23,7 @@ class Project extends Model
'icon',
'start_date',
'deadline',
'company_id',
// Agrega cualquier otro campo nuevo aquí
];
@@ -81,5 +83,8 @@ class Project extends Model
return $this->belongsToMany(Category::class);
}
public function company()
{
return $this->belongsTo(Company::class);
}
}

View File

@@ -10,6 +10,7 @@ use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Spatie\Permission\Traits\HasRoles;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class User extends Authenticatable
{
@@ -109,5 +110,17 @@ class User extends Authenticatable
{
return $this->profile_photo ? Storage::url($this->profile_photo) : asset('images/default-user.png');
}
public function companies(): BelongsToMany
{
return $this->belongsToMany(Company::class, 'company_contacts')
->withPivot('position')
->withTimestamps();
}
public function company()
{
return $this->belongsTo(Company::class);
}
}