first commit
This commit is contained in:
76
database/migrations/2024_12_15_110508_create_store_table.php
Normal file
76
database/migrations/2024_12_15_110508_create_store_table.php
Normal 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');
|
||||
|
||||
}
|
||||
};
|
@ -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');
|
||||
|
||||
}
|
||||
};
|
@ -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');
|
||||
}
|
||||
};
|
@ -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']);
|
||||
|
||||
}
|
||||
};
|
@ -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');
|
||||
}
|
||||
};
|
85
database/seeders/CurrencySeeder.php
Normal file
85
database/seeders/CurrencySeeder.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Koneko\VuexyStoreManager\Models\Currency;
|
||||
|
||||
class CurrencySeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Lista de divisas a insertar.
|
||||
*/
|
||||
protected static array $divisas = [
|
||||
[
|
||||
'c_currency' => 'MXN',
|
||||
'symbol' => '$',
|
||||
'used_in_purchases' => true,
|
||||
'used_in_sales' => true,
|
||||
'used_in_ecommerce' => false,
|
||||
'main_currency' => true,
|
||||
'auto_update_exchange_rates' => true,
|
||||
'update_interval' => 24,
|
||||
'status' => Currency::STATUS_ENABLED,
|
||||
],
|
||||
[
|
||||
'c_currency' => 'USD',
|
||||
'symbol' => '$',
|
||||
'used_in_purchases' => true,
|
||||
'used_in_sales' => true,
|
||||
'used_in_ecommerce' => false,
|
||||
'main_currency' => false,
|
||||
'auto_update_exchange_rates' => true,
|
||||
'update_interval' => 24,
|
||||
'status' => Currency::STATUS_ENABLED,
|
||||
],
|
||||
[
|
||||
'c_currency' => 'EUR',
|
||||
'symbol' => '€',
|
||||
'used_in_purchases' => true,
|
||||
'used_in_sales' => true,
|
||||
'used_in_ecommerce' => false,
|
||||
'main_currency' => false,
|
||||
'auto_update_exchange_rates' => true,
|
||||
'update_interval' => 24,
|
||||
'status' => Currency::STATUS_ENABLED,
|
||||
],
|
||||
[
|
||||
'c_currency' => 'GBP',
|
||||
'symbol' => '£',
|
||||
'used_in_purchases' => true,
|
||||
'used_in_sales' => false,
|
||||
'used_in_ecommerce' => false,
|
||||
'main_currency' => false,
|
||||
'auto_update_exchange_rates' => true,
|
||||
'update_interval' => 24,
|
||||
'status' => Currency::STATUS_ENABLED,
|
||||
],
|
||||
[
|
||||
'c_currency' => 'JPY',
|
||||
'symbol' => '¥',
|
||||
'used_in_purchases' => true,
|
||||
'used_in_sales' => false,
|
||||
'used_in_ecommerce' => false,
|
||||
'main_currency' => false,
|
||||
'auto_update_exchange_rates' => true,
|
||||
'update_interval' => 24,
|
||||
'status' => Currency::STATUS_ENABLED,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
foreach (self::$divisas as $divisa) {
|
||||
Currency::updateOrCreate(
|
||||
['c_currency' => $divisa['c_currency']], // Clave única
|
||||
$divisa // Valores a insertar/actualizar
|
||||
);
|
||||
}
|
||||
|
||||
$this->command->info('Divisas insertadas/actualizadas correctamente.');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user