Inicialización del módulo base
This commit is contained in:
71
src/modules/App/Models/ContactableAddress.php
Normal file
71
src/modules/App/Models/ContactableAddress.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models;
|
||||
|
||||
use Modules\Admin\App\Models\Sat\CodigoPostal;
|
||||
use Modules\Admin\App\Models\Sat\Colonia;
|
||||
use Modules\Admin\App\Models\Sat\Estado;
|
||||
use Modules\Admin\App\Models\Sat\Municipio;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContactableAddress extends Model
|
||||
{
|
||||
protected $table = 'contactable_addresses';
|
||||
|
||||
protected $fillable = [
|
||||
'contactable_id',
|
||||
'contactable_type',
|
||||
'type',
|
||||
'c_estado',
|
||||
'c_municipio',
|
||||
'c_codigo_postal',
|
||||
'c_colonia',
|
||||
'direccion',
|
||||
'num_ext',
|
||||
'num_int',
|
||||
'referencia',
|
||||
'lat',
|
||||
'lng',
|
||||
'preference_level',
|
||||
];
|
||||
|
||||
/**
|
||||
* Casts for the model attributes.
|
||||
*/
|
||||
protected $casts = [
|
||||
'lat' => 'float',
|
||||
'lng' => 'float',
|
||||
'preference_level' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Polymorphic relationship to the parent model.
|
||||
*/
|
||||
public function contactable()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationships to SAT tables.
|
||||
*/
|
||||
public function estado()
|
||||
{
|
||||
return $this->belongsTo(Estado::class, 'c_estado', 'c_estado');
|
||||
}
|
||||
|
||||
public function municipio()
|
||||
{
|
||||
return $this->belongsTo(Municipio::class, 'c_municipio', 'c_municipio');
|
||||
}
|
||||
|
||||
public function codigoPostal()
|
||||
{
|
||||
return $this->belongsTo(CodigoPostal::class, 'c_codigo_postal', 'c_codigo_postal');
|
||||
}
|
||||
|
||||
public function colonia()
|
||||
{
|
||||
return $this->belongsTo(Colonia::class, 'c_colonia', 'c_colonia');
|
||||
}
|
||||
}
|
35
src/modules/App/Models/ContactableItem.php
Normal file
35
src/modules/App/Models/ContactableItem.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContactableItem extends Model
|
||||
{
|
||||
protected $table = 'contactable_items';
|
||||
|
||||
protected $fillable = [
|
||||
'contactable_id',
|
||||
'contactable_type',
|
||||
'type',
|
||||
'data_contact',
|
||||
'is_preferred',
|
||||
'preference_level',
|
||||
];
|
||||
|
||||
/**
|
||||
* Casts for the model attributes.
|
||||
*/
|
||||
protected $casts = [
|
||||
'is_preferred' => 'boolean',
|
||||
'preference_level' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Polymorphic relationship to the parent model.
|
||||
*/
|
||||
public function contactable()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
}
|
62
src/modules/App/Models/MediaItem.php
Normal file
62
src/modules/App/Models/MediaItem.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MediaItem extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'url',
|
||||
'imageable_type',
|
||||
'imageable_id',
|
||||
'type',
|
||||
'sub_type',
|
||||
'url',
|
||||
'path',
|
||||
'title',
|
||||
'description',
|
||||
'order',
|
||||
];
|
||||
|
||||
// the list of types values that can be stored in table
|
||||
const TYPE_CARD = 1;
|
||||
const TYPE_BANNER = 2;
|
||||
const TYPE_COVER = 3;
|
||||
const TYPE_GALLERY = 4;
|
||||
const TYPE_BANNER_HOME = 5;
|
||||
const TYPE_CARD2 = 6;
|
||||
const TYPE_BANNER2 = 7;
|
||||
const TYPE_COVER2 = 8;
|
||||
|
||||
/**
|
||||
* List of names for each types.
|
||||
* @var array
|
||||
*/
|
||||
public static $typesList = [
|
||||
self::TYPE_CARD => 'Card',
|
||||
self::TYPE_BANNER => 'Banner',
|
||||
self::TYPE_COVER => 'Cover',
|
||||
self::TYPE_GALLERY => 'Gallery',
|
||||
self::TYPE_BANNER_HOME => 'Banner Home',
|
||||
self::TYPE_CARD2 => 'Card 2',
|
||||
self::TYPE_BANNER2 => 'Banner 2',
|
||||
self::TYPE_COVER2 => 'Cover 2',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the parent imageable model (user or post).
|
||||
*/
|
||||
public function imageable()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
}
|
50
src/modules/App/Models/Sat/Banco.php
Normal file
50
src/modules/App/Models/Sat/Banco.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Banco extends Model
|
||||
{
|
||||
// the list of status values that can be stored in table
|
||||
const STATUS_ENABLED = 10;
|
||||
const STATUS_DISABLED = 1;
|
||||
|
||||
/**
|
||||
* List of names for each status.
|
||||
* @var array
|
||||
*/
|
||||
public static $statusList = [
|
||||
self::STATUS_ENABLED => 'Habilitado',
|
||||
self::STATUS_DISABLED => 'Deshabilitado',
|
||||
];
|
||||
|
||||
/**
|
||||
* List of names for each status.
|
||||
* @var array
|
||||
*/
|
||||
public static $statusListClass = [
|
||||
self::STATUS_ENABLED => 'success',
|
||||
self::STATUS_DISABLED => 'warning',
|
||||
];
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_banco';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_banco',
|
||||
'descripcion',
|
||||
'razon_social',
|
||||
'rfc',
|
||||
'status',
|
||||
];
|
||||
}
|
33
src/modules/App/Models/Sat/ClaveProdServ.php
Normal file
33
src/modules/App/Models/Sat/ClaveProdServ.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ClaveProdServ extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_clave_prod_serv';
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_clave_prod_serv',
|
||||
'descripcion',
|
||||
'incluir_iva_trasladado',
|
||||
'incluir_ieps_trasladado',
|
||||
'complemento_que_debe_incluir',
|
||||
'fecha_inicio_vigencia',
|
||||
'fecha_fin_vigencia',
|
||||
'estimulo_franja_fronteriza',
|
||||
'palabras_similares',
|
||||
];
|
||||
}
|
42
src/modules/App/Models/Sat/ClaveUnidad.php
Normal file
42
src/modules/App/Models/Sat/ClaveUnidad.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ClaveUnidad extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_clave_unidad';
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_clave_unidad',
|
||||
'nombre',
|
||||
'descripcion',
|
||||
'nota',
|
||||
'fecha_de_inicio_de_vigencia',
|
||||
'fecha_de_fin_de_vigencia',
|
||||
'simbolo',
|
||||
'is_base',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'fecha_de_inicio_de_vigencia' => 'datetime',
|
||||
'fecha_de_fin_de_vigencia' => 'datetime',
|
||||
];
|
||||
}
|
77
src/modules/App/Models/Sat/CodigoPostal.php
Normal file
77
src/modules/App/Models/Sat/CodigoPostal.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class CodigoPostal extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_codigo_postal';
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_codigo_postal',
|
||||
'c_estado',
|
||||
'c_municipio',
|
||||
'c_localidad',
|
||||
'estimulo_franja_fronteriza',
|
||||
'fecha_inicio_de_vigencia',
|
||||
'fecha_fin_de_vigencia',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'fecha_inicio_de_vigencia' => 'datetime',
|
||||
'fecha_fin_de_vigencia' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the estado associated with the CodigoPostal.
|
||||
*/
|
||||
public function estado(): HasOne
|
||||
{
|
||||
return $this->hasOne(Estado::class, 'c_estado', 'c_estado');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the municipio associated with the CodigoPostal.
|
||||
*/
|
||||
public function municipio(): HasOne
|
||||
{
|
||||
return $this->hasOne(Municipio::class, 'c_municipio', 'c_municipio')
|
||||
->where('c_estado', $this->c_estado);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the localidad associated with the CodigoPostal.
|
||||
*/
|
||||
public function localidad(): HasOne
|
||||
{
|
||||
return $this->hasOne(Localidad::class, 'c_estado', 'c_estado')
|
||||
->where('c_localidad', $this->c_localidad);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the localidad associated with the CodigoPostal.
|
||||
*/
|
||||
public function colonias(): HasMany
|
||||
{
|
||||
return $this->hasMany(Colonia::class, 'c_codigo_postal', 'c_codigo_postal');
|
||||
}
|
||||
}
|
39
src/modules/App/Models/Sat/Colonia.php
Normal file
39
src/modules/App/Models/Sat/Colonia.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Colonia extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_colonia';
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_colonia',
|
||||
'c_codigo_postal',
|
||||
'nombre_del_asentamiento',
|
||||
];
|
||||
|
||||
|
||||
public static function selectList($c_codigo_postal, $c_colonia = false)
|
||||
{
|
||||
return self::select('c_colonia', 'nombre_del_asentamiento')
|
||||
->where('c_codigo_postal', $c_codigo_postal)
|
||||
->when($c_colonia, function ($query) use ($c_colonia) {
|
||||
$query->where('c_colonia', $c_colonia);
|
||||
})
|
||||
->orderBy('nombre_del_asentamiento')
|
||||
->pluck('nombre_del_asentamiento', 'c_colonia');
|
||||
}
|
||||
}
|
37
src/modules/App/Models/Sat/Deduccion.php
Normal file
37
src/modules/App/Models/Sat/Deduccion.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Deduccion extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_deduccion';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_deduccion',
|
||||
'descripcion',
|
||||
'fecha_inicio_de_vigencia',
|
||||
'fecha_fin_de_vigencia',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'fecha_inicio_de_vigencia' => 'datetime',
|
||||
'fecha_fin_de_vigencia' => 'datetime',
|
||||
];
|
||||
}
|
47
src/modules/App/Models/Sat/Estado.php
Normal file
47
src/modules/App/Models/Sat/Estado.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Estado extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_estado';
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_estado',
|
||||
'c_pais',
|
||||
'nombre_del_estado',
|
||||
'fecha_inicio_de_vigencia',
|
||||
'fecha_fin_de_vigencia',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'fecha_inicio_de_vigencia' => 'datetime',
|
||||
'fecha_fin_de_vigencia' => 'datetime',
|
||||
];
|
||||
|
||||
public static function selectList($pais = 'MEX')
|
||||
{
|
||||
return self::select('c_estado', 'nombre_del_estado')
|
||||
->where('c_pais', $pais)
|
||||
->orderBy('nombre_del_estado')
|
||||
->pluck('nombre_del_estado', 'c_estado');
|
||||
}
|
||||
}
|
53
src/modules/App/Models/Sat/FormaPago.php
Normal file
53
src/modules/App/Models/Sat/FormaPago.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FormaPago extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_forma_pago';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_forma_pago',
|
||||
'descripcion',
|
||||
'bancarizado',
|
||||
'numero_de_operacion',
|
||||
'rfc_del_emisor_de_la_cuenta_ordenante',
|
||||
'cuenta_ordenante',
|
||||
'patron_para_cuenta_ordenante',
|
||||
'rfc_del_emisor_cuenta_de_beneficiario',
|
||||
'cuenta_de_benenficiario',
|
||||
'patron_para_cuenta_beneficiaria',
|
||||
'tipo_cadena_pago',
|
||||
'banco_emisor_de_la_cuenta_ordenante',
|
||||
'fecha_inicio_de_vigencia',
|
||||
'fecha_fin_de_vigencia',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'fecha_inicio_de_vigencia' => 'datetime',
|
||||
'fecha_fin_de_vigencia' => 'datetime',
|
||||
];
|
||||
|
||||
public static function selectList()
|
||||
{
|
||||
return self::selectRaw('c_forma_pago, CONCAT(c_forma_pago, " - ", descripcion) as value')
|
||||
->pluck('value', 'c_forma_pago');
|
||||
}
|
||||
}
|
17
src/modules/App/Models/Sat/Impuestos.php
Normal file
17
src/modules/App/Models/Sat/Impuestos.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
class Impuestos
|
||||
{
|
||||
// Definición de constantes para c_impuesto
|
||||
const IMPUESTOS_ISR = 1;
|
||||
const IMPUESTOS_IVA = 2;
|
||||
const IMPUESTOS_IEPS = 3;
|
||||
|
||||
public static $catalogo = [
|
||||
self::IMPUESTOS_ISR => 'ISR',
|
||||
self::IMPUESTOS_IVA => 'IVA',
|
||||
self::IMPUESTOS_IEPS => 'IEPS',
|
||||
];
|
||||
}
|
39
src/modules/App/Models/Sat/Localidad.php
Normal file
39
src/modules/App/Models/Sat/Localidad.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Localidad extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_localidad';
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_localidad',
|
||||
'c_estado',
|
||||
'descripcion',
|
||||
'fecha_de_inicio_de_vigencia',
|
||||
'fecha_de_fin_de_vigencia',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'fecha_de_inicio_de_vigencia' => 'datetime',
|
||||
'fecha_de_fin_de_vigencia' => 'datetime',
|
||||
];
|
||||
}
|
14
src/modules/App/Models/Sat/MetodoPago.php
Normal file
14
src/modules/App/Models/Sat/MetodoPago.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
class MetodoPago
|
||||
{
|
||||
const METODO_PAGO_PUE = 'PUE';
|
||||
const METODO_PAGO_PPD = 'PPD';
|
||||
|
||||
public static $catalogo = [
|
||||
self::METODO_PAGO_PUE => 'Pago en una sola exhibición',
|
||||
self::METODO_PAGO_PPD => 'Pago en parcialidades o diferido',
|
||||
];
|
||||
}
|
46
src/modules/App/Models/Sat/Moneda.php
Normal file
46
src/modules/App/Models/Sat/Moneda.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Moneda extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_moneda';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_moneda',
|
||||
'descripcion',
|
||||
'decimales',
|
||||
'porcentaje_variacion',
|
||||
'fecha_inicio_de_vigencia',
|
||||
'fecha_fin_de_vigencia',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'fecha_inicio_de_vigencia' => 'datetime',
|
||||
'fecha_fin_de_vigencia' => 'datetime',
|
||||
];
|
||||
|
||||
|
||||
public static function selectList()
|
||||
{
|
||||
return self::selectRaw('c_moneda, CONCAT_WS(" ", c_moneda, "-", descripcion) as text')
|
||||
->pluck('text', 'c_moneda');
|
||||
}
|
||||
}
|
51
src/modules/App/Models/Sat/Municipio.php
Normal file
51
src/modules/App/Models/Sat/Municipio.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Municipio extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_municipio';
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_municipio',
|
||||
'c_estado',
|
||||
'descripcion',
|
||||
'fecha_de_inicio_de_vigencia',
|
||||
'fecha_de_fin_de_vigencia',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'fecha_de_inicio_de_vigencia' => 'datetime',
|
||||
'fecha_de_fin_de_vigencia' => 'datetime',
|
||||
];
|
||||
|
||||
|
||||
public static function selectList($c_estado, $c_municipio = false)
|
||||
{
|
||||
return self::select('c_municipio', 'descripcion')
|
||||
->where('c_estado', $c_estado)
|
||||
->when($c_municipio, function ($query) use ($c_municipio) {
|
||||
$query->where('c_municipio', $c_municipio);
|
||||
})
|
||||
->orderBy('descripcion')
|
||||
->pluck('descripcion', 'c_municipio');
|
||||
}
|
||||
}
|
21
src/modules/App/Models/Sat/ObjetoImp.php
Normal file
21
src/modules/App/Models/Sat/ObjetoImp.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
class ObjetoImp
|
||||
{
|
||||
// Definición de constantes para c_objeto_imp
|
||||
const OBJETO_IMP_NO_OBJETO = 1;
|
||||
const OBJETO_IMP_SI_OBJETO = 2;
|
||||
const OBJETO_IMP_SI_OBJETO_NO_DESGLOSE = 3;
|
||||
const OBJETO_IMP_SI_OBJETO_NO_CAUSA = 4;
|
||||
const OBJETO_IMP_SI_OBJETO_IVA_CREDITO = 5;
|
||||
|
||||
public static $catalogo = [
|
||||
self::OBJETO_IMP_NO_OBJETO => 'No objeto de impuesto.',
|
||||
self::OBJETO_IMP_SI_OBJETO => 'Sí objeto de impuesto.',
|
||||
self::OBJETO_IMP_SI_OBJETO_NO_DESGLOSE => 'Sí objeto del impuesto y no obligado al desglose.',
|
||||
self::OBJETO_IMP_SI_OBJETO_NO_CAUSA => 'Sí objeto del impuesto y no causa impuesto.',
|
||||
self::OBJETO_IMP_SI_OBJETO_IVA_CREDITO => 'Sí objeto del impuesto, IVA crédito PODEBI.',
|
||||
];
|
||||
}
|
39
src/modules/App/Models/Sat/Pais.php
Normal file
39
src/modules/App/Models/Sat/Pais.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Pais extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_pais';
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_pais',
|
||||
'descripcion',
|
||||
'formato_de_codigo_postal',
|
||||
'formato_de_registro_de_identidad_tributaria',
|
||||
'validacion_del_registro_de_identidad_tributaria',
|
||||
'agrupaciones',
|
||||
];
|
||||
|
||||
public static function selectList()
|
||||
{
|
||||
return self::select('c_pais', 'descripcion')
|
||||
->get()
|
||||
->mapWithKeys(function ($item) {
|
||||
return [$item->c_pais => $item->c_pais . ' - ' . $item->descripcion];
|
||||
});
|
||||
}
|
||||
}
|
37
src/modules/App/Models/Sat/Percepcion.php
Normal file
37
src/modules/App/Models/Sat/Percepcion.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Percepcion extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_percepcion';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_percepcion',
|
||||
'descripcion',
|
||||
'fecha_inicio_de_vigencia',
|
||||
'fecha_fin_de_vigencia',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'fecha_inicio_de_vigencia' => 'datetime',
|
||||
'fecha_fin_de_vigencia' => 'datetime',
|
||||
];
|
||||
}
|
21
src/modules/App/Models/Sat/Periodicidad.php
Normal file
21
src/modules/App/Models/Sat/Periodicidad.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
class Periodicidad
|
||||
{
|
||||
// Definición de constantes para c_periodicidad
|
||||
const PERIODICIDAD_DIARIO = 1;
|
||||
const PERIODICIDAD_SEMANAL = 2;
|
||||
const PERIODICIDAD_QUINCENAL = 3;
|
||||
const PERIODICIDAD_MENSUAL = 4;
|
||||
const PERIODICIDAD_BIMESTRAL = 5;
|
||||
|
||||
public static $catalogo = [
|
||||
self::PERIODICIDAD_DIARIO => 'Diario',
|
||||
self::PERIODICIDAD_SEMANAL => 'Semanal',
|
||||
self::PERIODICIDAD_QUINCENAL => 'Quincenal',
|
||||
self::PERIODICIDAD_MENSUAL => 'Mensual',
|
||||
self::PERIODICIDAD_BIMESTRAL => 'Bimestral',
|
||||
];
|
||||
}
|
33
src/modules/App/Models/Sat/PeriodicidadPago.php
Normal file
33
src/modules/App/Models/Sat/PeriodicidadPago.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
class PeriodicidadPago
|
||||
{
|
||||
// Definición de constantes para Tipos de Periodicidad de Pago
|
||||
const PERIODICIDAD_DIARIO = 1;
|
||||
const PERIODICIDAD_SEMANAL = 2;
|
||||
const PERIODICIDAD_CATORCENAL = 3;
|
||||
const PERIODICIDAD_QUINCENAL = 4;
|
||||
const PERIODICIDAD_MENSUAL = 5;
|
||||
const PERIODICIDAD_BIMESTRAL = 6;
|
||||
const PERIODICIDAD_UNIDAD_OBRA = 7;
|
||||
const PERIODICIDAD_COMISION = 8;
|
||||
const PERIODICIDAD_PRECIO_ALZADO = 9;
|
||||
const PERIODICIDAD_DECENAL = 10;
|
||||
const PERIODICIDAD_OTRA = 99;
|
||||
|
||||
public static $tipoPeriodicidad = [
|
||||
self::PERIODICIDAD_DIARIO => 'Diario',
|
||||
self::PERIODICIDAD_SEMANAL => 'Semanal',
|
||||
self::PERIODICIDAD_CATORCENAL => 'Catorcenal',
|
||||
self::PERIODICIDAD_QUINCENAL => 'Quincenal',
|
||||
self::PERIODICIDAD_MENSUAL => 'Mensual',
|
||||
self::PERIODICIDAD_BIMESTRAL => 'Bimestral',
|
||||
self::PERIODICIDAD_UNIDAD_OBRA => 'Unidad obra',
|
||||
self::PERIODICIDAD_COMISION => 'Comisión',
|
||||
self::PERIODICIDAD_PRECIO_ALZADO => 'Precio alzado',
|
||||
self::PERIODICIDAD_DECENAL => 'Decenal',
|
||||
self::PERIODICIDAD_OTRA => 'Otra Periodicidad'
|
||||
];
|
||||
}
|
46
src/modules/App/Models/Sat/RegimenFiscal.php
Normal file
46
src/modules/App/Models/Sat/RegimenFiscal.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RegimenFiscal extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_regimen_fiscal';
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_regimen_fiscal',
|
||||
'descripcion',
|
||||
'fisica',
|
||||
'moral',
|
||||
'fecha_de_inicio_de_vigencia',
|
||||
'fecha_de_fin_de_vigencia',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'fecha_de_inicio_de_vigencia' => 'datetime',
|
||||
'fecha_de_fin_de_vigencia' => 'datetime',
|
||||
];
|
||||
|
||||
public static function selectList()
|
||||
{
|
||||
return self::selectRaw('c_regimen_fiscal, CONCAT(c_regimen_fiscal, " - ", descripcion) as value')
|
||||
->pluck('value', 'c_regimen_fiscal');
|
||||
}
|
||||
}
|
21
src/modules/App/Models/Sat/TipoComprobante.php
Normal file
21
src/modules/App/Models/Sat/TipoComprobante.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
class TipoComprobante
|
||||
{
|
||||
// Definición de constantes para c_tipo_de_comprobante
|
||||
const TIPO_COMPROBANTE_INGRESO = 'I';
|
||||
const TIPO_COMPROBANTE_EGRESO = 'E';
|
||||
const TIPO_COMPROBANTE_TRASLADO = 'T';
|
||||
const TIPO_COMPROBANTE_NOMINA = 'N';
|
||||
const TIPO_COMPROBANTE_PAGO = 'P';
|
||||
|
||||
public static $catalogo = [
|
||||
self::TIPO_COMPROBANTE_INGRESO => 'Ingreso',
|
||||
self::TIPO_COMPROBANTE_EGRESO => 'Egreso',
|
||||
self::TIPO_COMPROBANTE_TRASLADO => 'Traslado',
|
||||
self::TIPO_COMPROBANTE_NOMINA => 'Nómina',
|
||||
self::TIPO_COMPROBANTE_PAGO => 'Pago',
|
||||
];
|
||||
}
|
17
src/modules/App/Models/Sat/TipoFactor.php
Normal file
17
src/modules/App/Models/Sat/TipoFactor.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
class TipoFactor
|
||||
{
|
||||
// Definición de constantes para c_tipo_factor
|
||||
const TIPO_FACTOR_TASA = 1;
|
||||
const TIPO_FACTOR_CUOTA = 2;
|
||||
const TIPO_FACTOR_EXENTO = 3;
|
||||
|
||||
public static $catalogo = [
|
||||
self::TIPO_FACTOR_TASA => 'Tasa',
|
||||
self::TIPO_FACTOR_CUOTA => 'Cuota',
|
||||
self::TIPO_FACTOR_EXENTO => 'Exento',
|
||||
];
|
||||
}
|
25
src/modules/App/Models/Sat/TipoRelacion.php
Normal file
25
src/modules/App/Models/Sat/TipoRelacion.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
class TipoRelacion
|
||||
{
|
||||
// Definición de constantes para c_tipo_relacion
|
||||
const TIPO_RELACION_NOTA_CREDITO = 1;
|
||||
const TIPO_RELACION_NOTA_DEBITO = 2;
|
||||
const TIPO_RELACION_DEVOLUCION_MERCANCIA = 3;
|
||||
const TIPO_RELACION_SUSTITUCION_CFDI = 4;
|
||||
const TIPO_RELACION_TRASLADOS_FACTURADOS = 5;
|
||||
const TIPO_RELACION_FACTURA_TRASLADOS = 6;
|
||||
const TIPO_RELACION_CFDI_ANTICIPO = 7;
|
||||
|
||||
public static $catalogo = [
|
||||
self::TIPO_RELACION_NOTA_CREDITO => 'Nota de crédito de los documentos relacionados',
|
||||
self::TIPO_RELACION_NOTA_DEBITO => 'Nota de débito de los documentos relacionados',
|
||||
self::TIPO_RELACION_DEVOLUCION_MERCANCIA => 'Devolución de mercancía sobre facturas o traslados previos',
|
||||
self::TIPO_RELACION_SUSTITUCION_CFDI => 'Sustitución de los CFDI previos',
|
||||
self::TIPO_RELACION_TRASLADOS_FACTURADOS => 'Traslados de mercancías facturados previamente',
|
||||
self::TIPO_RELACION_FACTURA_TRASLADOS => 'Factura generada por los traslados previos',
|
||||
self::TIPO_RELACION_CFDI_ANTICIPO => 'CFDI por aplicación de anticipo',
|
||||
];
|
||||
}
|
47
src/modules/App/Models/Sat/UsoCfdi.php
Normal file
47
src/modules/App/Models/Sat/UsoCfdi.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models\Sat;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UsoCfdi extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sat_uso_cfdi';
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'c_uso_cfdi',
|
||||
'descripcion',
|
||||
'aplica_para_tipo_persona_fisica',
|
||||
'aplica_para_tipo_persona_moral',
|
||||
'fecha_inicio_de_vigencia',
|
||||
'fecha_fin_de_vigencia',
|
||||
'regimen_fiscal_receptor',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'fecha_inicio_de_vigencia' => 'datetime',
|
||||
'fecha_fin_de_vigencia' => 'datetime',
|
||||
];
|
||||
|
||||
public static function selectList()
|
||||
{
|
||||
return self::selectRaw('c_uso_cfdi, CONCAT(c_uso_cfdi, " - ", descripcion) as value')
|
||||
->pluck('value', 'c_uso_cfdi');
|
||||
}
|
||||
}
|
39
src/modules/App/Models/Setting.php
Normal file
39
src/modules/App/Models/Setting.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'key',
|
||||
'value',
|
||||
'user_id',
|
||||
];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
// Relación con el usuario
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
// Scope para obtener configuraciones de un usuario específico
|
||||
public function scopeForUser($query, $userId)
|
||||
{
|
||||
return $query->where('user_id', $userId);
|
||||
}
|
||||
|
||||
// Configuraciones globales (sin usuario)
|
||||
public function scopeGlobal($query)
|
||||
{
|
||||
return $query->whereNull('user_id');
|
||||
}
|
||||
}
|
392
src/modules/App/Models/User.php
Normal file
392
src/modules/App/Models/User.php
Normal file
@ -0,0 +1,392 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Intervention\Image\Typography\FontFactory;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
|
||||
use OwenIt\Auditing\Auditable;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use Modules\Admin\App\Models\Sat\CodigoPostal;
|
||||
use Modules\Admin\App\Models\Sat\RegimenFiscal;
|
||||
use Modules\Admin\App\Models\Sat\UsoCfdi;
|
||||
use Modules\Admin\App\Notifications\CustomResetPasswordNotification;
|
||||
|
||||
class User extends Authenticatable implements MustVerifyEmail, AuditableContract
|
||||
{
|
||||
use HasRoles,
|
||||
HasApiTokens,
|
||||
HasFactory,
|
||||
Notifiable,
|
||||
TwoFactorAuthenticatable,
|
||||
Auditable;
|
||||
|
||||
// the list of status values that can be stored in table
|
||||
const STATUS_ENABLED = 10;
|
||||
const STATUS_DISABLED = 1;
|
||||
const STATUS_REMOVED = 0;
|
||||
|
||||
const AVATAR_DISK = 'public';
|
||||
const PROFILE_PHOTO_DIR = 'profile-photos/';
|
||||
const INITIAL_AVATAR_DIR = 'initial-avatars/';
|
||||
const INITIAL_MAX_LENGTH = 4;
|
||||
|
||||
const AVATAR_WIDTH = 512;
|
||||
const AVATAR_HEIGHT = 512;
|
||||
const AVATAR_BACKGROUND = '#EBF4FF'; // Fondo por defecto
|
||||
const AVATAR_COLORS = [
|
||||
'#7367f0',
|
||||
'#808390',
|
||||
'#28c76f',
|
||||
'#ff4c51',
|
||||
'#ff9f43',
|
||||
'#00bad1',
|
||||
'#4b4b4b',
|
||||
];
|
||||
|
||||
/**
|
||||
* List of names for each status.
|
||||
* @var array
|
||||
*/
|
||||
public static $statusList = [
|
||||
self::STATUS_ENABLED => 'Habilitado',
|
||||
self::STATUS_DISABLED => 'Deshabilitado',
|
||||
self::STATUS_REMOVED => 'Eliminado',
|
||||
];
|
||||
|
||||
/**
|
||||
* List of names for each status.
|
||||
* @var array
|
||||
*/
|
||||
public static $statusListClass = [
|
||||
self::STATUS_ENABLED => 'success',
|
||||
self::STATUS_DISABLED => 'warning',
|
||||
self::STATUS_REMOVED => 'danger',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'contact_code',
|
||||
'name',
|
||||
'last_name',
|
||||
'email',
|
||||
'password',
|
||||
'profile_photo_path',
|
||||
'company',
|
||||
'birth_date',
|
||||
'hire_date',
|
||||
'curp',
|
||||
'nss',
|
||||
'job_title',
|
||||
'face_vector',
|
||||
'rfc',
|
||||
'nombre_fiscal',
|
||||
'tipo_persona',
|
||||
'c_regimen_fiscal',
|
||||
'domicilio_fiscal',
|
||||
'c_uso_cfdi',
|
||||
'is_partner',
|
||||
'is_employee',
|
||||
'is_prospect',
|
||||
'is_customer',
|
||||
'is_provider',
|
||||
'is_user',
|
||||
'status',
|
||||
'created_by',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
'two_factor_recovery_codes',
|
||||
'two_factor_secret',
|
||||
];
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $appends = [
|
||||
'profile_photo_url',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'face_vector' => 'array',
|
||||
'birth_date' => 'date',
|
||||
'hire_date' => 'date',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attributes to include in the Audit.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $auditInclude = [
|
||||
'name',
|
||||
'email',
|
||||
];
|
||||
|
||||
|
||||
public function updateProfilePhoto(UploadedFile $image_avatar)
|
||||
{
|
||||
try {
|
||||
// Verificar si el archivo existe
|
||||
if (!file_exists($image_avatar->getRealPath()))
|
||||
throw new \Exception('El archivo no existe en la ruta especificada.');
|
||||
|
||||
if (!in_array($image_avatar->getClientOriginalExtension(), ['jpg', 'jpeg', 'png']))
|
||||
throw new \Exception('El formato del archivo debe ser JPG o PNG.');
|
||||
|
||||
// Directorio donde se guardarán los avatares
|
||||
$avatarDisk = self::AVATAR_DISK;
|
||||
$avatarPath = self::PROFILE_PHOTO_DIR;
|
||||
$avatarName = uniqid('avatar_') . '.png'; // Nombre único para el avatar
|
||||
|
||||
// Crear la instancia de ImageManager
|
||||
$driver = config('image.driver', 'gd');
|
||||
$manager = new ImageManager($driver);
|
||||
|
||||
// Crear el directorio si no existe
|
||||
if (!Storage::disk($avatarDisk)->exists($avatarPath))
|
||||
Storage::disk($avatarDisk)->makeDirectory($avatarPath);
|
||||
|
||||
// Leer la imagen
|
||||
$image = $manager->read($image_avatar->getRealPath());
|
||||
|
||||
// crop the best fitting 5:3 (600x360) ratio and resize to 600x360 pixel
|
||||
$image->cover(self::AVATAR_WIDTH, self::AVATAR_HEIGHT);
|
||||
|
||||
// Guardar la imagen en el disco de almacenamiento gestionado por Laravel
|
||||
Storage::disk($avatarDisk)->put($avatarPath . $avatarName, $image->toPng(indexed: true));
|
||||
|
||||
// Elimina el avatar existente si hay uno
|
||||
$this->deleteProfilePhoto();
|
||||
|
||||
// Update the user's profile photo path
|
||||
$this->forceFill([
|
||||
'profile_photo_path' => $avatarName,
|
||||
])->save();
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception('Ocurrió un error al actualizar el avatar. ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteProfilePhoto()
|
||||
{
|
||||
if (!empty($this->profile_photo_path)) {
|
||||
$avatarDisk = self::AVATAR_DISK;
|
||||
|
||||
Storage::disk($avatarDisk)->delete($this->profile_photo_path);
|
||||
|
||||
$this->forceFill([
|
||||
'profile_photo_path' => null,
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function getAvatarColor()
|
||||
{
|
||||
// Selecciona un color basado en el id del usuario
|
||||
return self::AVATAR_COLORS[$this->id % count(self::AVATAR_COLORS)];
|
||||
}
|
||||
|
||||
|
||||
public static function getAvatarImage($name, $color, $background, $size)
|
||||
{
|
||||
$avatarDisk = self::AVATAR_DISK;
|
||||
$directory = self::INITIAL_AVATAR_DIR;
|
||||
$initials = self::getInitials($name);
|
||||
|
||||
$cacheKey = "avatar-{$initials}-{$color}-{$background}-{$size}";
|
||||
$path = "{$directory}/{$cacheKey}.png";
|
||||
$storagePath = storage_path("app/public/{$path}");
|
||||
|
||||
// Verificar si el avatar ya está en caché
|
||||
if (Storage::disk($avatarDisk)->exists($path))
|
||||
return response()->file($storagePath);
|
||||
|
||||
// Crear el avatar
|
||||
$image = self::createAvatarImage($name, $color, $background, $size);
|
||||
|
||||
// Guardar en el directorio de iniciales
|
||||
Storage::disk($avatarDisk)->put($path, $image->toPng(indexed: true));
|
||||
|
||||
// Retornar la imagen directamente
|
||||
return response()->file($storagePath);
|
||||
}
|
||||
|
||||
private static function createAvatarImage($name, $color, $background, $size)
|
||||
{
|
||||
// Usar la configuración del driver de imagen
|
||||
$driver = config('image.driver', 'gd');
|
||||
$manager = new ImageManager($driver);
|
||||
|
||||
$initials = self::getInitials($name);
|
||||
|
||||
// Crear la imagen con fondo
|
||||
$image = $manager->create($size, $size)
|
||||
->fill($background);
|
||||
|
||||
// Escribir texto en la imagen
|
||||
$image->text(
|
||||
$initials,
|
||||
$size / 2, // Centrar horizontalmente
|
||||
$size / 2, // Centrar verticalmente
|
||||
function (FontFactory $font) use ($color, $size) {
|
||||
$font->file(base_path('/modules/Admin/Resources/assets/vendor/fonts/OpenSans/static/OpenSans-Bold.ttf'));
|
||||
$font->size($size * 0.4);
|
||||
$font->color($color);
|
||||
$font->align('center');
|
||||
$font->valign('middle');
|
||||
}
|
||||
);
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
public static function getInitials($name)
|
||||
{
|
||||
// Manejar casos de nombres vacíos o nulos
|
||||
if (empty($name))
|
||||
return 'NA';
|
||||
|
||||
// Usar array_map para mayor eficiencia
|
||||
$initials = implode('', array_map(function ($word) {
|
||||
return mb_substr($word, 0, 1);
|
||||
}, explode(' ', $name)));
|
||||
|
||||
$initials = substr($initials, 0, self::INITIAL_MAX_LENGTH);
|
||||
|
||||
return strtoupper($initials);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getProfilePhotoUrlAttribute()
|
||||
{
|
||||
if ($this->profile_photo_path)
|
||||
return Storage::url(self::PROFILE_PHOTO_DIR . '/' . $this->profile_photo_path);
|
||||
|
||||
// Generar URL del avatar por iniciales
|
||||
$name = urlencode($this->fullname);
|
||||
$color = ltrim($this->getAvatarColor(), '#');
|
||||
$background = ltrim(self::AVATAR_BACKGROUND, '#');
|
||||
$size = (self::AVATAR_WIDTH + self::AVATAR_HEIGHT) / 2;
|
||||
|
||||
return url("/admin/usuario/avatar?name={$name}&color={$color}&background={$background}&size={$size}");
|
||||
}
|
||||
|
||||
public function getFullnameAttribute()
|
||||
{
|
||||
return trim($this->name . ' ' . $this->last_name);
|
||||
}
|
||||
|
||||
public function getInitialsAttribute()
|
||||
{
|
||||
return self::getInitials($this->fullname);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Envía la notificación de restablecimiento de contraseña.
|
||||
*
|
||||
* @param string $token
|
||||
*/
|
||||
public function sendPasswordResetNotification($token)
|
||||
{
|
||||
// Usar la notificación personalizada
|
||||
$this->notify(new CustomResetPasswordNotification($token));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Relations
|
||||
*/
|
||||
|
||||
// User who created this user
|
||||
public function creator()
|
||||
{
|
||||
return $this->belongsTo(self::class, 'created_by');
|
||||
}
|
||||
|
||||
// Regimen fiscal
|
||||
public function regimenFiscal()
|
||||
{
|
||||
return $this->belongsTo(RegimenFiscal::class, 'c_regimen_fiscal', 'c_regimen_fiscal');
|
||||
}
|
||||
|
||||
// Domicilio fiscal
|
||||
public function domicilioFiscal()
|
||||
{
|
||||
return $this->belongsTo(CodigoPostal::class, 'domicilio_fiscal', 'c_codigo_postal');
|
||||
}
|
||||
|
||||
// Uso de CFDI
|
||||
public function usoCfdi()
|
||||
{
|
||||
return $this->belongsTo(UsoCfdi::class, 'c_uso_cfdi', 'c_uso_cfdi');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper methods
|
||||
*/
|
||||
|
||||
public function isActive()
|
||||
{
|
||||
return $this->status === 1;
|
||||
}
|
||||
|
||||
public function isPartner()
|
||||
{
|
||||
return $this->is_partner === 1;
|
||||
}
|
||||
|
||||
public function isEmployee()
|
||||
{
|
||||
return $this->is_employee === 1;
|
||||
}
|
||||
|
||||
public function isCustomer()
|
||||
{
|
||||
return $this->is_customer === 1;
|
||||
}
|
||||
|
||||
public function isProvider()
|
||||
{
|
||||
return $this->is_provider === 1;
|
||||
}
|
||||
}
|
14
src/modules/App/Models/UserLogin.php
Normal file
14
src/modules/App/Models/UserLogin.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserLogin extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'ip_address',
|
||||
'user_agent'
|
||||
];
|
||||
}
|
Reference in New Issue
Block a user