diff --git a/src/components/supplies/add-goods-modal.tsx b/src/components/supplies/add-goods-modal.tsx index 89976c3..9d81b21 100644 --- a/src/components/supplies/add-goods-modal.tsx +++ b/src/components/supplies/add-goods-modal.tsx @@ -1,6 +1,6 @@ 'use client' -import { Package, Plus, Minus, X, FileText, Settings, ShoppingCart } from 'lucide-react' +import { Package, Plus, Minus, X, Settings, ShoppingCart } from 'lucide-react' import Image from 'next/image' import React, { useState } from 'react' diff --git a/src/components/supplies/create-suppliers-supply-page.tsx b/src/components/supplies/create-suppliers-supply-page.tsx index 3ccae5d..4034ad9 100644 --- a/src/components/supplies/create-suppliers-supply-page.tsx +++ b/src/components/supplies/create-suppliers-supply-page.tsx @@ -1,15 +1,7 @@ 'use client' import { useMutation, useQuery } from '@apollo/client' -import { - ArrowLeft, - Building2, - Package, - Plus, - Search, - ShoppingCart, - X, -} from 'lucide-react' +import { ArrowLeft, Building2, Package, Plus, Search, ShoppingCart, X } from 'lucide-react' import Image from 'next/image' import { useRouter } from 'next/navigation' import { useState } from 'react' @@ -24,11 +16,11 @@ import { Input } from '@/components/ui/input' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { CREATE_SUPPLY_ORDER } from '@/graphql/mutations' import { - GET_AVAILABLE_SUPPLIES_FOR_RECIPE, - GET_COUNTERPARTY_SERVICES, - GET_COUNTERPARTY_SUPPLIES, - GET_MY_COUNTERPARTIES, - GET_ORGANIZATION_PRODUCTS, + GET_AVAILABLE_SUPPLIES_FOR_RECIPE, + GET_COUNTERPARTY_SERVICES, + GET_COUNTERPARTY_SUPPLIES, + GET_MY_COUNTERPARTIES, + GET_ORGANIZATION_PRODUCTS, } from '@/graphql/queries' import { useAuth } from '@/hooks/useAuth' import { useSidebar } from '@/hooks/useSidebar' @@ -90,7 +82,7 @@ interface SelectedGoodsItem { parameters?: Array<{ name: string; value: string }> // Параметры товара } -interface LogisticsCompany { +interface _LogisticsCompany { id: string name: string estimatedCost: number @@ -272,7 +264,7 @@ export function CreateSuppliersSupplyPage() { const _wbCards: WBCard[] = [] // Временно отключено // Показываем только партнеров с типом WHOLESALE согласно rules2.md 13.3 - const wholesaleSuppliers = allCounterparties.filter((cp: any) => { + const wholesaleSuppliers = allCounterparties.filter((cp: GoodsSupplier) => { try { return cp && cp.type === 'WHOLESALE' } catch (error) { @@ -301,7 +293,7 @@ export function CreateSuppliersSupplyPage() { // Получаем товары выбранного поставщика согласно rules2.md 13.3 // Теперь фильтрация происходит на сервере через GraphQL запрос - const products = (productsData?.organizationProducts || []).filter((product: any) => { + const products = (productsData?.organizationProducts || []).filter((product: GoodsProduct) => { try { return product && product.id && product.name } catch (error) { @@ -357,7 +349,7 @@ export function CreateSuppliersSupplyPage() { const logisticsCompanies = allCounterparties?.filter((partner) => partner.type === 'LOGIST') || [] // Моковые фулфилмент-центры согласно rules2.md 9.7.2 - const fulfillmentCenters = [ + const _fulfillmentCenters = [ { id: 'ff1', name: 'СФ Центр Москва', address: 'г. Москва, ул. Складская 10' }, { id: 'ff2', name: 'СФ Центр СПб', address: 'г. Санкт-Петербург, пр. Логистический 5' }, { id: 'ff3', name: 'СФ Центр Екатеринбург', address: 'г. Екатеринбург, ул. Промышленная 15' }, @@ -378,7 +370,7 @@ export function CreateSuppliersSupplyPage() { // Removed unused updateProductQuantity function // Добавление товара в корзину из карточки с заданным количеством - const addToCart = (product: GoodsProduct) => { + const _addToCart = (product: GoodsProduct) => { const quantity = getProductQuantity(product.id) if (quantity <= 0) { toast.error('Укажите количество товара') @@ -513,7 +505,7 @@ export function CreateSuppliersSupplyPage() { } // Расчет стоимости компонентов рецептуры - const calculateRecipeCost = (productId: string) => { + const _calculateRecipeCost = (productId: string) => { const recipe = productRecipes[productId] if (!recipe) return { services: 0, consumables: 0, total: 0 } @@ -582,8 +574,8 @@ export function CreateSuppliersSupplyPage() { selectedQuantity: quantity, unit: product.unit, category: product.category?.name, - supplierId: selectedSupplier!.id, - supplierName: selectedSupplier!.name || selectedSupplier!.fullName || '', + supplierId: selectedSupplier?.id || '', + supplierName: selectedSupplier?.name || selectedSupplier?.fullName || '', completeness: additionalData?.completeness, recipe: additionalData?.recipe, specialRequirements: additionalData?.specialRequirements, @@ -610,33 +602,33 @@ export function CreateSuppliersSupplyPage() { // Функция расчета полной стоимости товара с рецептурой const getProductTotalWithRecipe = (productId: string, quantity: number) => { - const product = allSelectedProducts.find(p => p.id === productId) + const product = allSelectedProducts.find((p) => p.id === productId) if (!product) return 0 - + const baseTotal = product.price * quantity const recipe = productRecipes[productId] - + if (!recipe) return baseTotal - + // Услуги ФФ const servicesCost = (recipe.selectedServices || []).reduce((sum, serviceId) => { - const service = fulfillmentServices.find(s => s.id === serviceId) + const service = fulfillmentServices.find((s) => s.id === serviceId) return sum + (service ? service.price * quantity : 0) }, 0) - + // Расходники ФФ const ffConsumablesCost = (recipe.selectedFFConsumables || []).reduce((sum, consumableId) => { - const consumable = fulfillmentConsumables.find(c => c.id === consumableId) + const consumable = fulfillmentConsumables.find((c) => c.id === consumableId) // Используем такую же логику как в карточке - только price return sum + (consumable ? consumable.price * quantity : 0) }, 0) - + // Расходники селлера const sellerConsumablesCost = (recipe.selectedSellerConsumables || []).reduce((sum, consumableId) => { - const consumable = sellerConsumables.find(c => c.id === consumableId) + const consumable = sellerConsumables.find((c) => c.id === consumableId) return sum + (consumable ? (consumable.pricePerUnit || 0) * quantity : 0) }, 0) - + return baseTotal + servicesCost + ffConsumablesCost + sellerConsumablesCost } @@ -644,14 +636,15 @@ export function CreateSuppliersSupplyPage() { const totalGoodsAmount = selectedGoods.reduce((sum, item) => { return sum + getProductTotalWithRecipe(item.id, item.selectedQuantity) }, 0) - - const totalQuantity = selectedGoods.reduce((sum, item) => sum + item.selectedQuantity, 0) + + const _totalQuantity = selectedGoods.reduce((sum, item) => sum + item.selectedQuantity, 0) const totalAmount = totalGoodsAmount // Валидация формы согласно rules2.md 9.7.6 // Проверяем обязательность услуг фулфилмента согласно rules-complete.md const hasRequiredServices = selectedGoods.every((item) => productRecipes[item.id]?.selectedServices?.length > 0) + // Проверка валидности формы - все обязательные поля заполнены const isFormValid = selectedSupplier && selectedGoods.length > 0 && deliveryDate && selectedFulfillment && hasRequiredServices // Обязательно: каждый товар должен иметь услуги @@ -670,7 +663,7 @@ export function CreateSuppliersSupplyPage() { try { await createSupplyOrder({ variables: { - supplierId: selectedSupplier!.id, + supplierId: selectedSupplier?.id || '', fulfillmentCenterId: selectedFulfillment, items: selectedGoods.map((item) => ({ productId: item.id, @@ -707,8 +700,8 @@ export function CreateSuppliersSupplyPage() { const maxDate = new Date() maxDate.setDate(maxDate.getDate() + 90) - const minDateString = tomorrow.toISOString().split('T')[0] - const maxDateString = maxDate.toISOString().split('T')[0] + const _minDateString = tomorrow.toISOString().split('T')[0] + const _maxDateString = maxDate.toISOString().split('T')[0] return (
Фулфилмент-центр:
- {allCounterparties?.find(c => c.id === selectedFulfillment)?.name || - allCounterparties?.find(c => c.id === selectedFulfillment)?.fullName || - 'Выбранный центр'} + {allCounterparties?.find((c) => c.id === selectedFulfillment)?.name || + allCounterparties?.find((c) => c.id === selectedFulfillment)?.fullName || + 'Выбранный центр'}