first commit

This commit is contained in:
2025-03-05 20:43:35 -06:00
commit aa938a3cab
47 changed files with 4388 additions and 0 deletions

View File

@ -0,0 +1,76 @@
<?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('stores', function (Blueprint $table) {
$table->smallIncrements('id');
// Información general
$table->string('code', 16)->unique();
$table->string('name', 96)->index();
$table->mediumText('description')->nullable();
$table->unsignedMediumInteger('manager_id')->nullable()->index(); // sat_codigo_postal.
// Ubicación
$table->char('c_pais', 3)->charset('ascii')->collation('ascii_general_ci')->nullable()->index(); // sat_estado.
$table->unsignedMediumInteger('c_codigo_postal')->nullable()->index(); // sat_codigo_postal.
$table->string('c_estado', 3)->charset('ascii')->collation('ascii_general_ci')->nullable()->index(); // sat_estado.
$table->unsignedTinyInteger('c_localidad')->nullable()->index();
$table->unsignedSmallInteger('c_municipio')->nullable()->index(); // sat_municipio.
$table->unsignedMediumInteger('c_colonia')->nullable()->index(); // sat_colonia.
$table->string('direccion')->nullable();
$table->string('num_ext')->nullable();
$table->string('num_int')->nullable();
$table->decimal('lat', 9, 6)->nullable();
$table->decimal('lng', 9, 6)->nullable();
// Contacto
$table->string('email')->nullable();
$table->string('tel')->nullable();
$table->string('tel2')->nullable();
// Información fiscal
$table->string('rfc', 13)->nullable();
$table->string('nombre_fiscal')->nullable();
$table->unsignedSmallInteger('c_regimen_fiscal')->nullable()->index(); // sat_regimen_fiscal.
$table->unsignedMediumInteger('domicilio_fiscal')->nullable(); // sat_codigo_postal.
$table->boolean('show_on_website')->default(false)->index();
$table->boolean('enable_ecommerce')->default(false)->index();
$table->boolean('status')->default(true)->index();
// Auditoria
$table->timestamps(); // Campos created_at y updated_at
// Relaciones
$table->foreign('manager_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_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');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('stores');
}
};

View File

@ -0,0 +1,54 @@
<?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
{
// centros de trabajo o estaciones de producción
Schema::create('store_work_centers', function (Blueprint $table) {
$table->smallIncrements('id');
$table->unsignedSmallInteger('store_id')->index();
$table->string('code', 16)->nullable()->unique()->comment('Código único del centro de trabajo');
$table->string('name', 96)->index(); // Nombre del centro de trabajo
$table->mediumText('description')->nullable(); // Descripción del centro
$table->unsignedMediumInteger('manager_id')->nullable()->index(); // sat_codigo_postal.
$table->string('tel')->nullable();
$table->string('tel2')->nullable();
$table->decimal('lat', 9, 6)->nullable()->comment('Latitud de la ubicación del centros de trabajo');
$table->decimal('lng', 9, 6)->nullable()->comment('Longitud de la ubicación del centros de trabajo');
$table->unsignedTinyInteger('status')->index(); // 'active', 'inactive'
$table->timestamps();
// Indices
$table->unique(['store_id', 'name']);
// Relaciones
$table->foreign('store_id')->references('id')->on('stores')->onDelete('restrict');
$table->foreign('manager_id')->references('id')->on('users')->onUpdate('restrict')->onDelete('restrict');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('store_work_centers');
}
};

View File

@ -0,0 +1,38 @@
<?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('store_user_roles', function (Blueprint $table) {
$table->id();
$table->unsignedSmallInteger('store_id')->index();
$table->unsignedMediumInteger('user_id')->index();
$table->unsignedBigInteger('role_id')->index();
//Auditoria
$table->timestamps();
// Relaciones
$table->foreign('store_id')->references('id')->on('stores')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('store_user_roles');
}
};

View File

@ -0,0 +1,63 @@
<?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('currencies', function (Blueprint $table) {
$table->smallIncrements('id');
$table->char('c_currency', 3)->charset('ascii')->collation('ascii_general_ci')->unique();
$table->string('symbol', 10)->nullable();
$table->boolean('auto_update_exchange_rates')->default(true);
$table->unsignedInteger('refresh_interval')->default(24); // Tiempo de actualización en horas
$table->decimal('adjustment_percent', 5, 2)->default(0); // Ajuste porcentual opcional
$table->boolean('status');
// Auditoria
$table->timestamps();
// Relaciones
$table->foreign('c_currency')->references('c_moneda')->on('sat_moneda')->onUpdate('restrict')->onDelete('restrict');
});
Schema::create('currency_exchange_rates', function (Blueprint $table) {
$table->id();
$table->char('c_currency', 3)->charset('ascii')->collation('ascii_general_ci');
$table->decimal('exchange_rate', 10, 4);
$table->date('exchange_date'); // Se almacena la fecha de la tasa de cambio
$table->string('source'); // Fuente (banxico, fixer, etc.)
$table->unsignedMediumInteger('updated_by')->nullable(); // Usuario que hizo el cambio
$table->text('comments')->nullable(); // Comentarios sobre la modificación
// Auditori
$table->timestamps();
// Indicies
$table->unique(['c_currency', 'exchange_date', 'source']); // Evita duplicados
$table->index(['c_currency', 'exchange_date']);
// Llaves foráneas
$table->foreign('c_currency')->references('c_currency')->on('currencies')->onDelete('cascade');
$table->foreign('updated_by')->references('id')->on('users')->onDelete('set null'); // Relación con usuarios
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists(['currencies', 'currency_exchange_rates']);
}
};

View File

@ -0,0 +1,53 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Query\IndexHint;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('email_transactions', function (Blueprint $table) {
$table->mediumIncrements('id');
// Relación polimórfica: puede ser un pedido, una factura, etc.
$table->unsignedMediumInteger('emailable_id')->index();
$table->string('emailable_type')->index();
$table->unsignedTinyInteger('email_provider')->index(); // Proveedor en CONST en modelo
$table->string('smtp_server')->nullable(); // Servidor SMTP personalizado
$table->string('smtp_port')->nullable(); // Puerto SMTP personalizado
$table->string('smtp_username')->nullable(); // Nombre de usuario para autenticación SMTP
$table->string('subject'); // Asunto del correo
$table->mediumtext('body'); // Cuerpo del correo
$table->string('recipient'); // Destinatario principal
$table->json('cc')->nullable(); // Destinatarios en copia (CC), separados por coma
$table->json('bcc')->nullable(); // Destinatarios en copia oculta (BCC), separados por coma
$table->string('reply_to')->nullable(); // Dirección de correo para respuestas
$table->string('sender_name')->nullable(); // Nombre del remitente
$table->string('sender_email')->nullable(); // Correo electrónico del remitente
$table->unsignedTinyInteger('status')->index()->comment('0: Pendiente, 1: En proceso, 2: Enviado, 3: Fallido, 4: En cola');
$table->mediumtext('error_message')->nullable(); // Mensaje de error si el envío falla
// Authoría
$table->unsignedMediumInteger('created_by')->index(); // Usuario que creó el registro
$table->timestamps();
// Índices
$table->index(['emailable_type', 'emailable_id']);
// Auditoría
$table->foreign('created_by')->references('id')->on('users')->onDelete('restrict');
});
}
public function down(): void
{
Schema::dropIfExists('email_transactions');
}
};