trim($row['categoria'])], ['is_active' => true] ); $categoryId = $category->id; } // Crear el producto en inventario $inventory = Inventory::create([ 'name' => trim($row['nombre']), 'sku' => !empty($row['sku']) ? trim($row['sku']) : null, 'category_id' => $categoryId, 'stock' => (int) $row['stock'], 'is_active' => true, ]); // Crear el precio del producto Price::create([ 'inventory_id' => $inventory->id, 'cost' => (float) $row['costo'], 'retail_price' => (float) $row['precio_venta'], 'tax' => !empty($row['impuesto']) ? (float) $row['impuesto'] : 0, ]); $this->imported++; return $inventory; } catch (\Exception $e) { $this->skipped++; $this->errors[] = "Error en fila: " . $e->getMessage(); return null; } } /** * Reglas de validación para cada fila */ public function rules(): array { return InventoryImportRequest::rowRules(); } /** * Mensajes personalizados de validación */ public function customValidationMessages() { return InventoryImportRequest::rowMessages(); } /** * Batch insert size */ public function batchSize(): int { return 100; } /** * Chunk size for reading */ public function chunkSize(): int { return 100; } /** * Obtener estadísticas de la importación */ public function getStats(): array { return [ 'imported' => $this->imported, 'skipped' => $this->skipped, 'errors' => $this->errors, ]; } }