first commit

This commit is contained in:
2025-03-05 21:11:33 -06:00
commit ac40d0f399
46 changed files with 6283 additions and 0 deletions

View File

@ -0,0 +1,85 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('code', 50)->unique()->nullable()->comment('Código único del contacto')->after('id');
$table->unsignedMediumInteger('parent_id')->nullable()->index()->after('code');
$table->unsignedMediumInteger('agent_id')->nullable()->index()->after('parent_id');
$table->string('company', 100)->nullable()->comment('Nombre de la empresa')->index()->after('email_verified_at');
$table->date('birth_date')->nullable()->comment('Fecha de nacimiento')->after('company');
$table->date('hire_date')->nullable()->comment('Fecha de contratación')->after('birth_date');
$table->string('curp', 50)->nullable()->comment('Clave Única de Registro de Población (CURP)')->index()->after('hire_date');
$table->string('nss', 11)->nullable()->comment('Número de seguridad social')->index()->after('curp');
$table->string('job_title', 100)->nullable()->comment('Cargo del contacto en la empresa')->after('nss');
$table->string('rfc', 13)->unique()->nullable()->index()->after('job_title');
$table->string('nombre_fiscal')->nullable()->index()->after('rfc');
$table->unsignedTinyInteger('tipo_persona')->nullable()->index()->after('nombre_fiscal');
$table->unsignedSmallInteger('c_regimen_fiscal')->nullable()->index()->after('tipo_persona');
$table->unsignedMediumInteger('domicilio_fiscal')->nullable()->index()->after('c_regimen_fiscal');
$table->char('c_uso_cfdi', 4)->charset('ascii')->collation('ascii_general_ci')->nullable()->index()->after('domicilio_fiscal');
$table->mediumText('note')->nullable()->after('c_uso_cfdi');
$table->unsignedTinyInteger('is_partner')->nullable()->index()->after('profile_photo_path');
$table->unsignedTinyInteger('is_employee')->nullable()->index()->after('is_partner');
$table->unsignedTinyInteger('is_prospect')->nullable()->index()->after('is_employee');
$table->unsignedTinyInteger('is_customer')->nullable()->index()->after('is_prospect');
$table->unsignedTinyInteger('is_provider')->nullable()->index()->after('is_customer');
$table->unsignedTinyInteger('is_user')->nullable()->index()->after('is_provider');
$table->text('notes')->nullable()->after('is_user');
$table->foreign('parent_id')
->references('id')
->on('users')
->onUpdate('restrict')
->onDelete('restrict');
$table->foreign('agent_id')
->references('id')
->on('users')
->onUpdate('restrict')
->onDelete('restrict');
$table->foreign('c_regimen_fiscal')
->references('c_regimen_fiscal')
->on('sat_regimen_fiscal')
->onUpdate('restrict')
->onDelete('restrict');
$table->foreign('domicilio_fiscal')
->references('c_codigo_postal')
->on('sat_codigo_postal')
->onUpdate('restrict')
->onDelete('restrict');
$table->foreign('c_uso_cfdi')
->references('c_uso_cfdi')
->on('sat_uso_cfdi')
->onUpdate('restrict')
->onDelete('restrict');
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropForeign(['created_by', 'c_regimen_fiscal', 'domicilio_fiscal', 'c_uso_cfdi']);
$table->dropColumn([
'c_regimen_fiscal', 'domicilio_fiscal', 'c_uso_cfdi',
'code', 'company', 'birth_date', 'hire_date',
'curp', 'nss', 'job_title', 'rfc', 'nombre_fiscal', 'tipo_persona',
'is_partner', 'is_employee', 'is_prospect', 'is_customer', 'is_provider', 'is_user'
]);
});
}
};

View File

@ -0,0 +1,99 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('contactable_addresses', function (Blueprint $table) {
$table->mediumIncrements('id');
// Relación optimizada (sin morphs por rendimiento)
$table->unsignedMediumInteger('contactable_id')->index();
$table->string('contactable_type')->index();
// Tipo de dirección
$table->unsignedTinyInteger('type')->index();
// Ubicación basada en el SAT
$table->char('c_pais', 3)->charset('ascii')->collation('ascii_general_ci')->nullable()->index();
$table->unsignedMediumInteger('c_codigo_postal')->nullable()->index();
$table->char('c_estado', 3)->charset('ascii')->collation('ascii_general_ci')->nullable()->index();
$table->unsignedTinyInteger('c_localidad')->nullable()->index();
$table->unsignedSmallInteger('c_municipio')->nullable()->index();
$table->unsignedMediumInteger('c_colonia')->nullable()->index();
// Datos de la dirección
$table->string('direccion')->nullable();
$table->string('num_ext')->nullable();
$table->string('num_int')->nullable();
$table->string('referencia')->nullable();
$table->decimal('lat', 9, 6)->nullable();
$table->decimal('lng', 9, 6)->nullable();
// Preferencia
$table->unsignedTinyInteger('preference_level')->nullable();
// Notas o comentarios
$table->text('notes')->nullable(); // Nuevo campo para comentarios
// Autoría
$table->timestamps();
// Índices
$table->index(['contactable_type', 'contactable_id']);
$table->index(['contactable_type', 'contactable_id', 'type']);
$table->index(['c_municipio', 'c_estado']);
// Relaciones con catálogos SAT
$table->foreign('c_pais')->references('c_pais')->on('sat_pais')->onUpdate('restrict')->onDelete('restrict');
$table->foreign('c_codigo_postal')->references('c_codigo_postal')->on('sat_codigo_postal')->onUpdate('restrict')->onDelete('restrict');
$table->foreign(['c_estado', 'c_pais'])->references(['c_estado', 'c_pais'])->on('sat_estado')->onUpdate('restrict')->onDelete('restrict');
$table->foreign(['c_municipio', 'c_estado'])->references(['c_municipio', 'c_estado'])->on('sat_municipio')->onUpdate('restrict')->onDelete('restrict');
$table->foreign(['c_localidad', 'c_estado'])->references(['c_localidad', 'c_estado'])->on('sat_localidad')->onUpdate('restrict')->onDelete('restrict');
$table->foreign(['c_colonia', 'c_codigo_postal'])->references(['c_colonia', 'c_codigo_postal'])->on('sat_colonia')->onUpdate('restrict')->onDelete('restrict');
});
Schema::create('contactable_items', function (Blueprint $table) {
$table->mediumIncrements('id');
// Relación optimizada
$table->unsignedMediumInteger('contactable_id')->index();
$table->string('contactable_type')->index();
// Tipo de medio de contacto (ej. 1=Email, 2=Teléfono, 3=WhatsApp)
$table->unsignedTinyInteger('type')->index();
// Dato de contacto (ej. email o teléfono)
$table->string('data_contact')->index();
// Preferencia
$table->unsignedTinyInteger('preference_level')->nullable();
// Notas o comentarios
$table->text('notes')->nullable(); // Nuevo campo para comentarios
// Autoría
$table->timestamps();
// Índices
$table->index(['contactable_type', 'contactable_id']);
$table->index(['contactable_type', 'contactable_id', 'type']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('contactable_addresses');
Schema::dropIfExists('contactable_items');
}
};