id(); $table->string('name', 150); $table->unsignedInteger('sort_order'); $table->boolean('is_active')->default(true); $table->timestamps(); }); Schema::create('stock_items', function (Blueprint $table) { $table->id(); $table->foreignId('stock_item_group_id')->constrained()->restrictOnDelete(); $table->string('name', 150); $table->string('unit', 20); $table->string('code', 150)->nullable(); $table->string('supplier', 150)->nullable(); $table->bigInteger('reorder_level_milli')->nullable(); $table->bigInteger('average_cost_hundredths')->default(0); $table->string('image_path')->nullable(); $table->string('thumbnail_path')->nullable(); $table->boolean('is_active')->default(true); $table->timestamps(); $table->index('code'); }); Schema::create('stock_movements', function (Blueprint $table) { $table->id(); $table->foreignId('stock_item_id')->constrained()->restrictOnDelete(); $table->string('kind', 20); $table->bigInteger('quantity_milli'); $table->bigInteger('unit_cost_hundredths'); $table->bigInteger('value_cents'); $table->date('occurred_on'); $table->timestamp('recorded_at'); $table->foreignId('user_id')->constrained()->restrictOnDelete(); $table->foreignId('task_id')->nullable()->constrained()->restrictOnDelete(); $table->foreignId('customer_job_id')->nullable()->constrained()->restrictOnDelete(); $table->unsignedBigInteger('machine_id')->nullable(); $table->unsignedBigInteger('quick_sale_order_line_id')->nullable(); $table->unsignedBigInteger('maintenance_record_id')->nullable(); $table->unsignedBigInteger('inventory_count_id')->nullable(); $table->foreignId('reverses_movement_id')->nullable()->unique()->constrained('stock_movements')->restrictOnDelete(); $table->string('reason')->nullable(); $table->string('supplier')->nullable(); $table->string('document_number')->nullable(); $table->timestamps(); $table->index(['stock_item_id', 'id']); $table->index(['occurred_on', 'kind']); $table->index('machine_id'); }); } public function down(): void { Schema::dropIfExists('stock_movements'); Schema::dropIfExists('stock_items'); Schema::dropIfExists('stock_item_groups'); } };