This commit is contained in:
Lizandro Guarnizo
2026-01-06 15:35:59 -05:00
commit a768146f65
602 changed files with 42505 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
*.sqlite*
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\AuthUser;
class AuthUserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = AuthUser::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'username' => fake()->userName(),
'password' => fake()->password(),
'last_login' => fake()->dateTime(),
'is_superuser' => fake()->boolean(),
'first_name' => fake()->firstName(),
'last_name' => fake()->lastName(),
'email' => fake()->safeEmail(),
'is_staff' => fake()->boolean(),
'is_active' => fake()->boolean(),
'date_joined' => fake()->dateTime(),
];
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Caja;
class CajaFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Caja::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'monto_inicial' => fake()->randomFloat(2, 0, 99999999.99),
'monto_final' => fake()->randomFloat(2, 0, 99999999.99),
'fecha_apertura' => fake()->dateTime(),
'fecha_cierre' => fake()->dateTime(),
'estado' => fake()->randomElement(["Abierta","Cerrada"]),
];
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Categoria;
class CategoriaFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Categoria::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'nombre' => fake()->regexify('[A-Za-z0-9]{255}'),
'descripcion' => fake()->text(),
];
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Cliente;
class ClienteFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Cliente::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'nombre' => fake()->regexify('[A-Za-z0-9]{255}'),
'correo' => fake()->regexify('[A-Za-z0-9]{255}'),
'telefono' => fake()->regexify('[A-Za-z0-9]{20}'),
'direccion' => fake()->text(),
'tipo_documento' => fake()->randomElement(["DNI","RUC","PASAPORTE"]),
'numero_documento' => fake()->regexify('[A-Za-z0-9]{20}'),
];
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Color;
class ColorFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Color::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'hex_code' => fake()->regexify('[A-Za-z0-9]{7}'),
];
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Compra;
use App\Models\Proveedore;
class CompraFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Compra::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'fecha' => fake()->dateTime(),
'proveedor_id' => Proveedore::factory(),
'total' => fake()->randomFloat(2, 0, 99999999.99),
'estado' => fake()->randomElement(["Recibida","Pendiente","Anulada"]),
];
}
}
@@ -0,0 +1,33 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Compra;
use App\Models\DetalleCompra;
use App\Models\Producto;
class DetalleCompraFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = DetalleCompra::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'compra_id' => Compra::factory(),
'producto_id' => Producto::factory(),
'cantidad' => fake()->numberBetween(-10000, 10000),
'precio_unitario' => fake()->randomFloat(2, 0, 99999999.99),
'subtotal' => fake()->randomFloat(2, 0, 99999999.99),
];
}
}
@@ -0,0 +1,33 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\DetalleVenta;
use App\Models\Producto;
use App\Models\Venta;
class DetalleVentaFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = DetalleVenta::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'venta_id' => Venta::factory(),
'producto_id' => Producto::factory(),
'cantidad' => fake()->numberBetween(-10000, 10000),
'precio_unitario' => fake()->randomFloat(2, 0, 99999999.99),
'subtotal' => fake()->randomFloat(2, 0, 99999999.99),
];
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Inventario;
use App\Models\Producto;
class InventarioFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Inventario::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'producto_id' => Producto::factory(),
'stock_actual' => fake()->numberBetween(-10000, 10000),
'stock_minimo' => fake()->numberBetween(-10000, 10000),
'ubicacion' => fake()->regexify('[A-Za-z0-9]{255}'),
];
}
}
@@ -0,0 +1,32 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Caja;
use App\Models\MovimientoCaja;
class MovimientoCajaFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = MovimientoCaja::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'caja_id' => Caja::factory(),
'tipo' => fake()->randomElement(["Ingreso","Egreso"]),
'monto' => fake()->randomFloat(2, 0, 99999999.99),
'descripcion' => fake()->text(),
'fecha' => fake()->dateTime(),
];
}
}
@@ -0,0 +1,31 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\ProductVariant;
class ProductVariantFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = ProductVariant::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'producto_id' => fake()->word(),
'color_id' => fake()->word(),
'size_id' => fake()->word(),
'stock' => fake()->numberBetween(-10000, 10000),
'sku' => fake()->regexify('[A-Za-z0-9]{50}'),
];
}
}
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Producto;
class ProductoFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Producto::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'nombre' => fake()->regexify('[A-Za-z0-9]{100}'),
'descripcion' => fake()->text(),
'codigo_barras' => fake()->regexify('[A-Za-z0-9]{50}'),
'precio_compra' => fake()->word(),
'precio_venta' => fake()->word(),
'stock' => fake()->numberBetween(-10000, 10000),
'categoria_id' => fake()->word(),
'estado' => fake()->boolean(),
];
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Proveedor;
class ProveedorFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Proveedor::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'nombre' => fake()->regexify('[A-Za-z0-9]{255}'),
'contacto' => fake()->regexify('[A-Za-z0-9]{255}'),
'telefono' => fake()->regexify('[A-Za-z0-9]{20}'),
'correo' => fake()->regexify('[A-Za-z0-9]{255}'),
'direccion' => fake()->text(),
];
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Role;
class RoleFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Role::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'description' => fake()->text(),
];
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Setting;
class SettingFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Setting::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'logo' => fake()->word(),
'description' => fake()->text(),
'primary_color' => fake()->word(),
'secondary_color' => fake()->word(),
'created_at' => fake()->dateTime(),
'updated_at' => fake()->dateTime(),
];
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Size;
class SizeFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Size::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'name' => fake()->name(),
];
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\User;
class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->safeEmail(),
'password' => fake()->password(),
];
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use App\Models\Cliente;
use App\Models\Venta;
class VentaFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Venta::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'fecha' => fake()->dateTime(),
'cliente_id' => Cliente::factory(),
'total' => fake()->randomFloat(2, 0, 99999999.99),
'tipo_pago' => fake()->randomElement(["Efectivo","Tarjeta","Transferencia"]),
'estado' => fake()->randomElement(["Pagado","Pendiente","Anulado"]),
];
}
}
@@ -0,0 +1,49 @@
<?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('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
Schema::dropIfExists('password_reset_tokens');
Schema::dropIfExists('sessions');
}
};
@@ -0,0 +1,35 @@
<?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('cache', function (Blueprint $table) {
$table->string('key')->primary();
$table->mediumText('value');
$table->integer('expiration');
});
Schema::create('cache_locks', function (Blueprint $table) {
$table->string('key')->primary();
$table->string('owner');
$table->integer('expiration');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('cache');
Schema::dropIfExists('cache_locks');
}
};
@@ -0,0 +1,57 @@
<?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('jobs', function (Blueprint $table) {
$table->id();
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->longText('failed_job_ids');
$table->mediumText('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('jobs');
Schema::dropIfExists('job_batches');
Schema::dropIfExists('failed_jobs');
}
};
@@ -0,0 +1,27 @@
<?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('role_user', function (Blueprint $table) {
$table->foreignId('role_id');
$table->foreignId('user_id');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('role_user');
}
};
@@ -0,0 +1,31 @@
<?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('settings', function (Blueprint $table) {
$table->id();
$table->string('logo')->nullable();
$table->text('description')->nullable();
$table->string('primary_color')->nullable();
$table->string('secondary_color')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('settings');
}
};
@@ -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::disableForeignKeyConstraints();
Schema::create('categorias', function (Blueprint $table) {
$table->id();
$table->string('nombre', 255);
$table->text('descripcion')->nullable();
$table->timestamps();
});
Schema::enableForeignKeyConstraints();
}
/**
* Reverse the migrations.
*/
public function down()
{
Schema::table('productos', function (Blueprint $table) {
$table->dropForeign(['categoria_id']); // Ajusta el nombre si es diferente
});
Schema::dropIfExists('categorias');
}
};
@@ -0,0 +1,35 @@
<?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::disableForeignKeyConstraints();
Schema::create('clientes', function (Blueprint $table) {
$table->id();
$table->string('nombre', 255);
$table->string('correo', 255)->nullable();
$table->string('telefono', 20)->nullable();
$table->string('numero_documento', 20);
$table->timestamps();
});
Schema::enableForeignKeyConstraints();
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('clientes');
}
};
@@ -0,0 +1,36 @@
<?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::disableForeignKeyConstraints();
Schema::create('proveedors', function (Blueprint $table) {
$table->id();
$table->string('nombre', 255);
$table->string('contacto', 255)->nullable();
$table->string('telefono', 20)->nullable();
$table->string('correo', 255)->unique()->nullable();
$table->text('direccion')->nullable();
$table->timestamps();
});
Schema::enableForeignKeyConstraints();
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('proveedors');
}
};
@@ -0,0 +1,55 @@
<?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('productos', function (Blueprint $table) {
$table->id();
$table->string('nombre', 100);
$table->text('descripcion');
$table->string('codigo_barras', 50)->unique();
$table->string('precio_compra');
$table->string('precio_venta');
$table->integer('stock')->default(0);
$table->unsignedBigInteger('categoria_id'); // Cambio a unsignedBigInteger
$table->boolean('estado')->default(true);
$table->string('imagen');
$table->timestamps();
// Definir correctamente la clave foránea
$table->foreign('categoria_id')->references('id')->on('categorias')->onDelete('cascade')->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
// Verificar si las tablas existen antes de eliminar las claves foráneas
if (Schema::hasTable('detalle_ventas')) {
Schema::table('detalle_ventas', function (Blueprint $table) {
$table->dropForeign(['producto_id']);
});
}
if (Schema::hasTable('detalle_compras')) {
Schema::table('detalle_compras', function (Blueprint $table) {
$table->dropForeign(['producto_id']);
});
}
Schema::dropIfExists('productos');
}
};
@@ -0,0 +1,35 @@
<?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::disableForeignKeyConstraints();
Schema::create('ventas', function (Blueprint $table) {
$table->id();
$table->foreignId('cliente_id')->nullable()->constrained();
$table->decimal('total', 10, 2);
$table->enum('tipo_pago', ["Efectivo","Tarjeta","Transferencia"]);
$table->enum('estado', ["Pagado","Pendiente","Anulado"])->default('Pagado');
$table->timestamps();
});
Schema::enableForeignKeyConstraints();
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('ventas');
}
};
@@ -0,0 +1,36 @@
<?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::disableForeignKeyConstraints();
Schema::create('detalle_ventas', function (Blueprint $table) {
$table->id();
$table->foreignId('venta_id')->constrained();
$table->foreignId('producto_id')->constrained();
$table->integer('cantidad');
$table->decimal('precio_unitario', 10, 2);
$table->decimal('subtotal', 10, 2);
$table->timestamps();
});
Schema::enableForeignKeyConstraints();
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('detalle_ventas');
}
};
@@ -0,0 +1,34 @@
<?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::disableForeignKeyConstraints();
Schema::create('compras', function (Blueprint $table) {
$table->id();
$table->foreignId('proveedor_id')->nullable()->constrained('proveedors');
$table->decimal('total', 10, 2);
$table->enum('estado', ["Recibida","Pendiente","Anulada"])->default('Recibida');
$table->timestamps();
});
Schema::enableForeignKeyConstraints();
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('compras');
}
};
@@ -0,0 +1,36 @@
<?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::disableForeignKeyConstraints();
Schema::create('detalle_compras', function (Blueprint $table) {
$table->id();
$table->foreignId('compra_id')->constrained();
$table->foreignId('producto_id')->constrained();
$table->integer('cantidad');
$table->decimal('precio_unitario', 10, 2);
$table->decimal('subtotal', 10, 2);
$table->timestamps();
});
Schema::enableForeignKeyConstraints();
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('detalle_compras');
}
};
@@ -0,0 +1,37 @@
<?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::disableForeignKeyConstraints();
Schema::create('cajas', function (Blueprint $table) {
$table->id();
$table->decimal('monto_inicial', 10, 2);
$table->decimal('monto_final', 10, 2)->nullable();
$table->timestamp('fecha_apertura')->useCurrent(); // Corrección aquí
$table->timestamp('fecha_cierre')->nullable();
$table->enum('estado', ["Abierta", "Cerrada"])->default('Abierta');
$table->timestamps();
});
Schema::enableForeignKeyConstraints();
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('cajas');
}
};
@@ -0,0 +1,35 @@
<?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::disableForeignKeyConstraints();
Schema::create('movimiento_cajas', function (Blueprint $table) {
$table->id();
$table->foreignId('caja_id')->constrained();
$table->enum('tipo', ["Ingreso","Egreso"]);
$table->decimal('monto', 10, 2);
$table->text('descripcion')->nullable();
$table->timestamps();
});
Schema::enableForeignKeyConstraints();
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('movimiento_cajas');
}
};
@@ -0,0 +1,29 @@
<?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('colors', function (Blueprint $table) {
$table->id();
$table->string('name', 50);
$table->string('hex_code', 7);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('colors');
}
};
@@ -0,0 +1,28 @@
<?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('sizes', function (Blueprint $table) {
$table->id();
$table->string('name', 10);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('sizes');
}
};
@@ -0,0 +1,33 @@
<?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('product_variants', function (Blueprint $table) {
$table->id();
$table->foreignId('producto_id')->constrained('productos')->onDelete('cascade')->onUpdate('cascade');
$table->foreignId('color_id')->constrained('colors')->onDelete('cascade')->onUpdate('cascade');
$table->foreignId('size_id')->constrained('sizes')->onDelete('cascade')->onUpdate('cascade');
$table->integer('stock')->default(0);
$table->string('sku', 50)->unique();
$table->string('barcode')->unique()->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('product_variants');
}
};
@@ -0,0 +1,140 @@
<?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
{
$teams = config('permission.teams');
$tableNames = config('permission.table_names');
$columnNames = config('permission.column_names');
$pivotRole = $columnNames['role_pivot_key'] ?? 'role_id';
$pivotPermission = $columnNames['permission_pivot_key'] ?? 'permission_id';
if (empty($tableNames)) {
throw new \Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
}
if ($teams && empty($columnNames['team_foreign_key'] ?? null)) {
throw new \Exception('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
}
Schema::create($tableNames['permissions'], static function (Blueprint $table) {
// $table->engine('InnoDB');
$table->bigIncrements('id'); // permission id
$table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
$table->string('guard_name'); // For MyISAM use string('guard_name', 25);
$table->timestamps();
$table->unique(['name', 'guard_name']);
});
Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) {
// $table->engine('InnoDB');
$table->bigIncrements('id'); // role id
if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing
$table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable();
$table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index');
}
$table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
$table->string('guard_name'); // For MyISAM use string('guard_name', 25);
$table->timestamps();
if ($teams || config('permission.testing')) {
$table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']);
} else {
$table->unique(['name', 'guard_name']);
}
});
Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) {
$table->unsignedBigInteger($pivotPermission);
$table->string('model_type');
$table->unsignedBigInteger($columnNames['model_morph_key']);
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index');
$table->foreign($pivotPermission)
->references('id') // permission id
->on($tableNames['permissions'])
->onDelete('cascade');
if ($teams) {
$table->unsignedBigInteger($columnNames['team_foreign_key']);
$table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index');
$table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'],
'model_has_permissions_permission_model_type_primary');
} else {
$table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
'model_has_permissions_permission_model_type_primary');
}
});
Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) {
$table->unsignedBigInteger($pivotRole);
$table->string('model_type');
$table->unsignedBigInteger($columnNames['model_morph_key']);
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index');
$table->foreign($pivotRole)
->references('id') // role id
->on($tableNames['roles'])
->onDelete('cascade');
if ($teams) {
$table->unsignedBigInteger($columnNames['team_foreign_key']);
$table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index');
$table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'],
'model_has_roles_role_model_type_primary');
} else {
$table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'],
'model_has_roles_role_model_type_primary');
}
});
Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) {
$table->unsignedBigInteger($pivotPermission);
$table->unsignedBigInteger($pivotRole);
$table->foreign($pivotPermission)
->references('id') // permission id
->on($tableNames['permissions'])
->onDelete('cascade');
$table->foreign($pivotRole)
->references('id') // role id
->on($tableNames['roles'])
->onDelete('cascade');
$table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary');
});
app('cache')
->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
->forget(config('permission.cache.key'));
}
/**
* Reverse the migrations.
*/
public function down(): void
{
$tableNames = config('permission.table_names');
if (empty($tableNames)) {
throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
}
Schema::drop($tableNames['role_has_permissions']);
Schema::drop($tableNames['model_has_roles']);
Schema::drop($tableNames['model_has_permissions']);
Schema::drop($tableNames['roles']);
Schema::drop($tableNames['permissions']);
}
};
@@ -0,0 +1,28 @@
<?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('detalle_ventas', function (Blueprint $table) {
$table->unsignedBigInteger('variante_id')->nullable()->after('producto_id');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('detalle_ventas', function (Blueprint $table) {
$table->dropColumn('variante_id');
});
}
};
@@ -0,0 +1,28 @@
<?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('detalle_compras', function (Blueprint $table) {
$table->foreignId('variante_id')->nullable()->constrained('product_variants');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('detalle_compras', function (Blueprint $table) {
//
});
}
};
@@ -0,0 +1,28 @@
<?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('productos', function (Blueprint $table) {
$table->integer('stock_minimo')->default(0)->after('stock');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('productos', function (Blueprint $table) {
$table->dropColumn('stock_minimo');
});
}
};
@@ -0,0 +1,28 @@
<?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('productos', function (Blueprint $table) {
$table->integer('stock_maximo')->default(1000)->after('stock_minimo');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('productos', function (Blueprint $table) {
$table->dropColumn('stock_maximo');
});
}
};
@@ -0,0 +1,28 @@
<?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('productos', function (Blueprint $table) {
$table->string('unidad_medida')->default('unidad')->after('stock_maximo');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('productos', function (Blueprint $table) {
$table->dropColumn('unidad_medida');
});
}
};
@@ -0,0 +1,28 @@
<?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('bodegas', function (Blueprint $table) {
$table->id();
$table->string('nombre', 100)->unique();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('bodegas');
}
};
@@ -0,0 +1,37 @@
<?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('producto_bodega', function (Blueprint $table) {
$table->id();
$table->foreignId('producto_id')->constrained('productos')->onDelete('cascade');
$table->foreignId('bodega_id')->constrained('bodegas')->onDelete('cascade');
$table->integer('stock')->default(0);
$table->timestamps();
// Índice único para evitar duplicados
$table->unique(['producto_id', 'bodega_id']);
// Índices para optimizar consultas
$table->index(['producto_id', 'stock']);
$table->index(['bodega_id', 'stock']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('producto_bodega');
}
};
@@ -0,0 +1,39 @@
<?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('transferencias_bodega', function (Blueprint $table) {
$table->id();
$table->foreignId('producto_id')->constrained('productos')->onDelete('cascade');
$table->foreignId('bodega_origen_id')->constrained('bodegas')->onDelete('cascade');
$table->foreignId('bodega_destino_id')->constrained('bodegas')->onDelete('cascade');
$table->integer('cantidad');
$table->text('motivo')->nullable();
$table->foreignId('usuario_id')->constrained('users')->onDelete('cascade');
$table->timestamp('fecha_transferencia');
$table->timestamps();
// Índices para optimizar consultas
$table->index(['producto_id', 'fecha_transferencia']);
$table->index(['bodega_origen_id', 'fecha_transferencia']);
$table->index(['bodega_destino_id', 'fecha_transferencia']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('transferencias_bodega');
}
};
@@ -0,0 +1,37 @@
<?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('variante_bodega', function (Blueprint $table) {
$table->id();
$table->foreignId('variante_id')->constrained('product_variants')->onDelete('cascade');
$table->foreignId('bodega_id')->constrained('bodegas')->onDelete('cascade');
$table->integer('stock')->default(0);
$table->timestamps();
// Índice único para evitar duplicados
$table->unique(['variante_id', 'bodega_id']);
// Índices para optimizar consultas
$table->index(['variante_id', 'stock']);
$table->index(['bodega_id', 'stock']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('variante_bodega');
}
};
@@ -0,0 +1,37 @@
<?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('transferencias_bodega', function (Blueprint $table) {
$table->foreignId('variante_id')
->nullable()
->after('producto_id')
->constrained('product_variants')
->onDelete('cascade');
// Índice para optimizar consultas por variante
$table->index(['variante_id', 'fecha_transferencia']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('transferencias_bodega', function (Blueprint $table) {
$table->dropForeign(['variante_id']);
$table->dropIndex(['variante_id', 'fecha_transferencia']);
$table->dropColumn('variante_id');
});
}
};
@@ -0,0 +1,28 @@
<?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('productos', function (Blueprint $table) {
//
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('productos', function (Blueprint $table) {
//
});
}
};
@@ -0,0 +1,28 @@
<?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('productos', function (Blueprint $table) {
$table->text('descripcion')->nullable()->change();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('productos', function (Blueprint $table) {
$table->text('descripcion')->nullable(false)->change();
});
}
};
@@ -0,0 +1,52 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Log::info("Iniciando limpieza de stock en productos con variantes...");
// Buscar productos que tengan stock directo Y variantes
$productosConVariantes = DB::table('productos')
->where('stock', '>', 0)
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('product_variants')
->whereColumn('product_variants.producto_id', 'productos.id');
})
->get();
Log::info("Encontrados " . $productosConVariantes->count() . " productos con stock directo y variantes");
foreach ($productosConVariantes as $producto) {
$stockAnterior = $producto->stock;
// Limpiar el stock del producto principal
DB::table('productos')
->where('id', $producto->id)
->update(['stock' => 0]);
Log::info("Stock limpiado para producto ID {$producto->id}: {$stockAnterior} → 0");
}
Log::info("Limpieza de stock completada exitosamente");
}
/**
* Reverse the migrations.
*/
public function down(): void
{
// No se puede deshacer esta migración porque no sabemos cuál era el stock original
Log::info("Esta migración no se puede deshacer - el stock anterior no se puede recuperar");
}
};
@@ -0,0 +1,29 @@
<?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('detalle_compras', function (Blueprint $table) {
$table->foreignId('bodega_id')->nullable()->constrained('bodegas')->onDelete('set null');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('detalle_compras', function (Blueprint $table) {
$table->dropForeign(['bodega_id']);
$table->dropColumn('bodega_id');
});
}
};
@@ -0,0 +1,59 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Log::info("Configurando bodega por defecto en detalles de compra existentes...");
// Buscar o crear la bodega Principal
$bodegaPrincipal = DB::table('bodegas')
->where('nombre', 'Principal')
->first();
if (!$bodegaPrincipal) {
$bodegaPrincipalId = DB::table('bodegas')->insertGetId([
'nombre' => 'Principal',
'created_at' => now(),
'updated_at' => now(),
]);
Log::info("Bodega Principal creada con ID: {$bodegaPrincipalId}");
} else {
$bodegaPrincipalId = $bodegaPrincipal->id;
Log::info("Bodega Principal encontrada con ID: {$bodegaPrincipalId}");
}
// Actualizar detalles de compra sin bodega asignada
$detallesSinBodega = DB::table('detalle_compras')
->whereNull('bodega_id')
->update(['bodega_id' => $bodegaPrincipalId]);
Log::info("Actualizados {$detallesSinBodega} detalles de compra con bodega Principal");
}
/**
* Reverse the migrations.
*/
public function down(): void
{
// Opcional: remover las asignaciones de bodega
DB::table('detalle_compras')
->where('bodega_id', function ($query) {
$query->select('id')
->from('bodegas')
->where('nombre', 'Principal');
})
->update(['bodega_id' => null]);
Log::info("Eliminadas asignaciones de bodega Principal en detalles de compra");
}
};
@@ -0,0 +1,133 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
// Paso 1: Agregar columnas snapshot
Schema::table('detalle_compras', function (Blueprint $table) {
$table->string('producto_nombre_snapshot')->nullable()->after('producto_id');
$table->string('variante_info_snapshot')->nullable()->after('variante_id');
});
// Paso 2: Actualizar registros existentes con snapshot de información
try {
DB::unprepared("
UPDATE detalle_compras
SET producto_nombre_snapshot = productos.nombre
FROM productos
WHERE productos.id = detalle_compras.producto_id
AND detalle_compras.producto_id IS NOT NULL
AND detalle_compras.producto_nombre_snapshot IS NULL
");
} catch (\Exception $e) {
// Si falla, intentar con la sintaxis estándar
\Illuminate\Support\Facades\DB::table('detalle_compras')
->whereNotNull('producto_id')
->whereNull('producto_nombre_snapshot')
->get()
->each(function ($detalle) {
$producto = \Illuminate\Support\Facades\DB::table('productos')
->where('id', $detalle->producto_id)
->first();
if ($producto) {
\Illuminate\Support\Facades\DB::table('detalle_compras')
->where('id', $detalle->id)
->update(['producto_nombre_snapshot' => $producto->nombre]);
}
});
}
try {
DB::unprepared("
UPDATE detalle_compras
SET variante_info_snapshot = CONCAT(c.name, ' / ', s.name)
FROM product_variants pv
JOIN colors c ON c.id = pv.color_id
JOIN sizes s ON s.id = pv.size_id
WHERE pv.id = detalle_compras.variante_id
AND detalle_compras.variante_id IS NOT NULL
AND detalle_compras.variante_info_snapshot IS NULL
");
} catch (\Exception $e) {
// Si falla, intentar con la sintaxis estándar
\Illuminate\Support\Facades\DB::table('detalle_compras')
->whereNotNull('variante_id')
->whereNull('variante_info_snapshot')
->get()
->each(function ($detalle) {
$variante = \Illuminate\Support\Facades\DB::table('product_variants as pv')
->join('colors as c', 'c.id', '=', 'pv.color_id')
->join('sizes as s', 's.id', '=', 'pv.size_id')
->where('pv.id', $detalle->variante_id)
->select(\Illuminate\Support\Facades\DB::raw("CONCAT(c.name, ' / ', s.name) as info"))
->first();
if ($variante) {
\Illuminate\Support\Facades\DB::table('detalle_compras')
->where('id', $detalle->id)
->update(['variante_info_snapshot' => $variante->info]);
}
});
}
// Paso 3: Actualizar claves foráneas
Schema::table('detalle_compras', function (Blueprint $table) {
// Eliminar las claves foráneas existentes si existen
try {
$table->dropForeign(['producto_id']);
} catch (\Exception $e) {
// La clave foránea puede no existir
}
try {
$table->dropForeign(['variante_id']);
} catch (\Exception $e) {
// La clave foránea puede no existir
}
// Recrear las claves foráneas con SET NULL para preservar historial
$table->foreign('producto_id')
->references('id')
->on('productos')
->onDelete('set null');
$table->foreign('variante_id')
->references('id')
->on('product_variants')
->onDelete('set null');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('detalle_compras', function (Blueprint $table) {
// Revertir a las claves foráneas originales
$table->dropForeign(['producto_id']);
$table->dropForeign(['variante_id']);
$table->foreign('producto_id')
->references('id')
->on('productos')
->onDelete('restrict'); // Comportamiento original
$table->foreign('variante_id')
->references('id')
->on('product_variants')
->onDelete('restrict'); // Comportamiento original
// Eliminar los campos snapshot
$table->dropColumn(['producto_nombre_snapshot', 'variante_info_snapshot']);
});
}
};
@@ -0,0 +1,30 @@
<?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('detalle_compras', function (Blueprint $table) {
// Hacer nullable la columna producto_id
$table->unsignedBigInteger('producto_id')->nullable()->change();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('detalle_compras', function (Blueprint $table) {
// Revertir a NOT NULL (solo si no hay registros con NULL)
$table->unsignedBigInteger('producto_id')->nullable(false)->change();
});
}
};
@@ -0,0 +1,30 @@
<?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('detalle_compras', function (Blueprint $table) {
// Hacer nullable la columna variante_id si no lo es ya
$table->unsignedBigInteger('variante_id')->nullable()->change();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('detalle_compras', function (Blueprint $table) {
// Revertir a NOT NULL (solo si no hay registros con NULL)
$table->unsignedBigInteger('variante_id')->nullable(false)->change();
});
}
};
@@ -0,0 +1,137 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
// Paso 1: Agregar columnas snapshot
Schema::table('detalle_ventas', function (Blueprint $table) {
$table->string('producto_nombre_snapshot')->nullable()->after('producto_id');
$table->string('variante_info_snapshot')->nullable()->after('variante_id');
});
// Paso 2: Actualizar registros existentes con snapshot de información
// Usar DB::unprepared para evitar problemas de transacción en PostgreSQL
try {
DB::unprepared("
UPDATE detalle_ventas
SET producto_nombre_snapshot = productos.nombre
FROM productos
WHERE productos.id = detalle_ventas.producto_id
AND detalle_ventas.producto_id IS NOT NULL
AND detalle_ventas.producto_nombre_snapshot IS NULL
");
} catch (\Exception $e) {
// Si falla, intentar con la sintaxis estándar
\Illuminate\Support\Facades\DB::table('detalle_ventas')
->whereNotNull('producto_id')
->whereNull('producto_nombre_snapshot')
->get()
->each(function ($detalle) {
$producto = \Illuminate\Support\Facades\DB::table('productos')
->where('id', $detalle->producto_id)
->first();
if ($producto) {
\Illuminate\Support\Facades\DB::table('detalle_ventas')
->where('id', $detalle->id)
->update(['producto_nombre_snapshot' => $producto->nombre]);
}
});
}
try {
DB::unprepared("
UPDATE detalle_ventas
SET variante_info_snapshot = CONCAT(c.name, ' / ', s.name)
FROM product_variants pv
JOIN colors c ON c.id = pv.color_id
JOIN sizes s ON s.id = pv.size_id
WHERE pv.id = detalle_ventas.variante_id
AND detalle_ventas.variante_id IS NOT NULL
AND detalle_ventas.variante_info_snapshot IS NULL
");
} catch (\Exception $e) {
// Si falla, intentar con la sintaxis estándar
\Illuminate\Support\Facades\DB::table('detalle_ventas')
->whereNotNull('variante_id')
->whereNull('variante_info_snapshot')
->get()
->each(function ($detalle) {
$variante = \Illuminate\Support\Facades\DB::table('product_variants as pv')
->join('colors as c', 'c.id', '=', 'pv.color_id')
->join('sizes as s', 's.id', '=', 'pv.size_id')
->where('pv.id', $detalle->variante_id)
->select(\Illuminate\Support\Facades\DB::raw("CONCAT(c.name, ' / ', s.name) as info"))
->first();
if ($variante) {
\Illuminate\Support\Facades\DB::table('detalle_ventas')
->where('id', $detalle->id)
->update(['variante_info_snapshot' => $variante->info]);
}
});
}
// Paso 3: Hacer nullable las columnas producto_id y variante_id
Schema::table('detalle_ventas', function (Blueprint $table) {
$table->unsignedBigInteger('producto_id')->nullable()->change();
$table->unsignedBigInteger('variante_id')->nullable()->change();
});
// Paso 4: Actualizar claves foráneas para usar SET NULL
try {
Schema::table('detalle_ventas', function (Blueprint $table) {
$table->dropForeign(['producto_id']);
$table->dropForeign(['variante_id']);
$table->foreign('producto_id')
->references('id')
->on('productos')
->onDelete('set null');
$table->foreign('variante_id')
->references('id')
->on('product_variants')
->onDelete('set null');
});
} catch (\Exception $e) {
// Las claves foráneas pueden no existir
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('detalle_ventas', function (Blueprint $table) {
// Revertir claves foráneas
$table->dropForeign(['producto_id']);
$table->dropForeign(['variante_id']);
$table->foreign('producto_id')
->references('id')
->on('productos')
->onDelete('restrict');
$table->foreign('variante_id')
->references('id')
->on('product_variants')
->onDelete('restrict');
// Revertir a NOT NULL (solo si no hay registros con NULL)
$table->unsignedBigInteger('producto_id')->nullable(false)->change();
$table->unsignedBigInteger('variante_id')->nullable(false)->change();
// Eliminar campos snapshot
$table->dropColumn(['producto_nombre_snapshot', 'variante_info_snapshot']);
});
}
};
@@ -0,0 +1,52 @@
<?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
{
// Solo hacer nullable las columnas si no lo son ya
Schema::table('detalle_ventas', function (Blueprint $table) {
$table->unsignedBigInteger('producto_id')->nullable()->change();
});
// Actualizar claves foráneas para usar SET NULL
try {
Schema::table('detalle_ventas', function (Blueprint $table) {
$table->dropForeign(['producto_id']);
$table->foreign('producto_id')
->references('id')
->on('productos')
->onDelete('set null');
});
} catch (\Exception $e) {
// La clave foránea puede no existir
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('detalle_ventas', function (Blueprint $table) {
try {
$table->dropForeign(['producto_id']);
$table->foreign('producto_id')
->references('id')
->on('productos')
->onDelete('restrict');
} catch (\Exception $e) {
// La clave foránea puede no existir
}
});
}
};
@@ -0,0 +1,30 @@
<?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('detalle_ventas', function (Blueprint $table) {
$table->foreignId('bodega_id')->nullable()->constrained('bodegas')->onDelete('set null');
$table->index('bodega_id');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('detalle_ventas', function (Blueprint $table) {
$table->dropForeign(['bodega_id']);
$table->dropColumn('bodega_id');
});
}
};
@@ -0,0 +1,64 @@
<?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('detalle_ventas', function (Blueprint $table) {
// Primero hacer la columna nullable si no lo es
$table->unsignedBigInteger('producto_id')->nullable()->change();
// Eliminar la clave foránea existente usando el nombre exacto
$table->dropForeign('detalle_ventas_producto_id_foreign');
// Recrear la clave foránea con SET NULL
$table->foreign('producto_id')
->references('id')
->on('productos')
->onDelete('set null');
});
// También crear clave foránea para variante_id (no existe actualmente según la consulta)
if (Schema::hasColumn('detalle_ventas', 'variante_id')) {
Schema::table('detalle_ventas', function (Blueprint $table) {
// variante_id ya es nullable
// Crear la clave foránea con SET NULL (no existe actualmente)
$table->foreign('variante_id')
->references('id')
->on('product_variants')
->onDelete('set null');
});
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('detalle_ventas', function (Blueprint $table) {
// Revertir las claves foráneas a RESTRICT
$table->dropForeign(['producto_id']);
$table->foreign('producto_id')
->references('id')
->on('productos')
->onDelete('restrict');
if (Schema::hasColumn('detalle_ventas', 'variante_id')) {
$table->dropForeign(['variante_id']);
// No recrear variante_id foreign key en down ya que no existía originalmente
}
// Revertir producto_id a NOT NULL
$table->unsignedBigInteger('producto_id')->nullable(false)->change();
});
}
};
@@ -0,0 +1,31 @@
<?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('detalle_ventas', function (Blueprint $table) {
$table->decimal('precio_original', 10, 2)->nullable()->after('precio_unitario');
$table->decimal('descuento_aplicado', 10, 2)->default(0)->after('precio_original');
$table->foreignId('usuario_modifico_precio_id')->nullable()->constrained('users')->after('descuento_aplicado');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('detalle_ventas', function (Blueprint $table) {
$table->dropForeign(['usuario_modifico_precio_id']);
$table->dropColumn(['precio_original', 'descuento_aplicado', 'usuario_modifico_precio_id']);
});
}
};
@@ -0,0 +1,41 @@
<?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('detalle_ventas', function (Blueprint $table) {
// Eliminar la foreign key existente
$table->dropForeign(['venta_id']);
// Recrear la foreign key con onDelete cascade
$table->foreign('venta_id')
->references('id')
->on('ventas')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('detalle_ventas', function (Blueprint $table) {
// Eliminar la foreign key con cascade
$table->dropForeign(['venta_id']);
// Recrear la foreign key sin cascade (estado original)
$table->foreign('venta_id')
->references('id')
->on('ventas');
});
}
};
@@ -0,0 +1,28 @@
<?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('detalle_compras', function (Blueprint $table) {
$table->string('DetalleCompra', 255)->nullable()->after('subtotal');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('detalle_compras', function (Blueprint $table) {
$table->dropColumn('DetalleCompra');
});
}
};
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
class CrudPermissionSeeder extends Seeder
{
public function run()
{
// Crear permisos
$permissions = [
'ver administracion',
'ver usuarios',
'ver roles',
'ver ajustes',
'ver inventario',
'ver colores',
'ver productos',
'ver sizes',
'ver variantes de productos',
];
foreach ($permissions as $permission) {
Permission::firstOrCreate(['name' => $permission, 'guard_name' => 'web']);
}
// Crear roles
$adminRole = Role::firstOrCreate(['name' => 'Administrador']);
$userRole = Role::firstOrCreate(['name' => 'Usuario']);
// Asignar permisos a roles
$adminRole->givePermissionTo($permissions); // Admin puede ver todo
$userRole->givePermissionTo([
'ver inventario',
'ver colores',
'ver productos',
'ver sizes',
'ver variantes de productos',
]); // Usuario solo puede ver Inventario
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace Database\Seeders;
use App\Models\User;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
// User::factory(10)->create();
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
]);
}
}