84 lines
2.3 KiB
PHP
Executable File
84 lines
2.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
#[Fillable(['username', 'name', 'email', 'password', 'commission_percentage', 'monthly_salary', 'is_active', 'fecha_ingreso', 'razon_social', 'sueldo_integro_diario'])]
|
|
#[Hidden(['password', 'remember_token'])]
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasFactory, Notifiable;
|
|
|
|
protected $guarded = [];
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'commission_percentage' => 'decimal:2',
|
|
'monthly_salary' => 'decimal:2',
|
|
'sueldo_integro_diario' => 'decimal:2',
|
|
'fecha_ingreso' => 'date',
|
|
'is_active' => 'boolean',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Relación con cuenta de Telegram
|
|
*/
|
|
public function telegramAccount(): HasOne
|
|
{
|
|
return $this->hasOne(TelegramAccount::class);
|
|
}
|
|
|
|
/**
|
|
* Relación con meses de trabajo
|
|
*/
|
|
public function months(): HasMany
|
|
{
|
|
return $this->hasMany(Month::class);
|
|
}
|
|
|
|
/**
|
|
* Relación con ventas diarias
|
|
*/
|
|
public function dailySales(): HasMany
|
|
{
|
|
return $this->hasMany(DailySale::class);
|
|
}
|
|
|
|
/**
|
|
* Relación con gastos
|
|
*/
|
|
public function expenses(): HasMany
|
|
{
|
|
return $this->hasMany(Expense::class);
|
|
}
|
|
|
|
/**
|
|
* Obtener el mes activo (si existe)
|
|
*/
|
|
public function getCurrentMonth(): ?Month
|
|
{
|
|
return $this->months()
|
|
->where('status', 'open')
|
|
->orderBy('year', 'desc')
|
|
->orderByRaw("FIELD(name, 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre')")
|
|
->first();
|
|
}
|
|
} |