const { PrismaClient } = require('@prisma/client') const prisma = new PrismaClient() async function checkFulfillmentUser() { try { console.log('🔍 ПОИСК ПОЛЬЗОВАТЕЛЯ +7 (999) 999-99-99...') // Ищем пользователя по номеру телефона const user = await prisma.user.findFirst({ where: { phone: '+7 (999) 999-99-99' }, include: { organization: { select: { id: true, name: true, type: true } } } }) if (!user) { console.log('❌ Пользователь с номером +7 (999) 999-99-99 не найден') return } console.log('👤 ПОЛЬЗОВАТЕЛЬ НАЙДЕН:') console.log(' ID:', user.id) console.log(' Телефон:', user.phone) console.log(' Организация:', user.organization?.name || 'Нет') console.log(' Тип организации:', user.organization?.type || 'Нет') if (user.organization?.type === 'FULFILLMENT') { console.log('\n📦 ПРОВЕРЯЕМ СКЛАД ФУЛФИЛМЕНТА:') // Проверяем Supply записи для фулфилмента const supplies = await prisma.supply.findMany({ where: { organizationId: user.organization.id, type: 'FULFILLMENT_CONSUMABLES' }, select: { id: true, name: true, article: true, currentStock: true, quantity: true, status: true, supplier: true, createdAt: true }, orderBy: { updatedAt: 'desc' } }) console.log('\n📋 РАСХОДНИКИ ФУЛФИЛМЕНТА:', supplies.length, 'позиций') if (supplies.length === 0) { console.log(' 📭 Склад пуст - нет расходников') } else { supplies.forEach((supply, index) => { console.log(`\n ${index + 1}. "${supply.name}"`) console.log(` Артикул: ${supply.article || 'Нет'}`) console.log(` Остаток: ${supply.currentStock} шт`) console.log(` Всего: ${supply.quantity} шт`) console.log(` Поставщик: ${supply.supplier || 'Нет'}`) console.log(` Статус: ${supply.status}`) console.log(` Создан: ${supply.createdAt.toISOString().split('T')[0]}`) }) const totalStock = supplies.reduce((sum, s) => sum + s.currentStock, 0) console.log(`\n📊 ИТОГО на складе: ${totalStock} шт`) } } else { console.log('⚠️ Пользователь не является фулфилментом') console.log(' Тип организации:', user.organization?.type) } } catch (error) { console.error('❌ Ошибка:', error.message) } finally { await prisma.$disconnect() } } checkFulfillmentUser()