diff --git a/src/app/fulfillment-supplies/detailed-supplies/page.tsx b/src/app/fulfillment-supplies/detailed-supplies/page.tsx
index 3205375..99f2008 100644
--- a/src/app/fulfillment-supplies/detailed-supplies/page.tsx
+++ b/src/app/fulfillment-supplies/detailed-supplies/page.tsx
@@ -2,8 +2,8 @@ import { FulfillmentDetailedSuppliesTab } from '@/components/fulfillment-supplie
export default function DetailedSuppliesPage() {
return (
-
+
)
-}
\ No newline at end of file
+}
diff --git a/src/components/fulfillment-supplies/fulfillment-supplies-layout.tsx b/src/components/fulfillment-supplies/fulfillment-supplies-layout.tsx
index 7133e04..0f2cc48 100644
--- a/src/components/fulfillment-supplies/fulfillment-supplies-layout.tsx
+++ b/src/components/fulfillment-supplies/fulfillment-supplies-layout.tsx
@@ -1,7 +1,18 @@
'use client'
import { useQuery } from '@apollo/client'
-import { Building2, ShoppingCart, Package, Wrench, RotateCcw, Clock, FileText, CheckCircle, ChevronRight, Home } from 'lucide-react'
+import {
+ Building2,
+ ShoppingCart,
+ Package,
+ Wrench,
+ RotateCcw,
+ Clock,
+ FileText,
+ CheckCircle,
+ ChevronRight,
+ Home,
+} from 'lucide-react'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import React from 'react'
@@ -26,37 +37,35 @@ function NotificationBadge({ count }: { count: number }) {
function Breadcrumbs({ pathname }: { pathname: string }) {
const getBreadcrumbs = (path: string) => {
const segments = path.split('/').filter(Boolean)
-
- const breadcrumbs = [
- { name: 'Главная', href: '/dashboard', icon: Home }
- ]
+
+ const breadcrumbs = [{ name: 'Главная', href: '/dashboard', icon: Home }]
if (segments[0] === 'fulfillment-supplies') {
breadcrumbs.push({ name: 'Входящие поставки', href: '/fulfillment-supplies', icon: Building2 })
-
+
if (segments[1]) {
const categoryMap: Record
= {
- 'goods': 'Товары',
+ goods: 'Товары',
'detailed-supplies': 'Расходники фулфилмента',
- 'consumables': 'Расходники селлеров',
- 'returns': 'Возвраты с ПВЗ'
+ consumables: 'Расходники селлеров',
+ returns: 'Возвраты с ПВЗ',
}
-
+
const category = categoryMap[segments[1]]
if (category) {
- breadcrumbs.push({
- name: category,
+ breadcrumbs.push({
+ name: category,
href: segments[2] ? `/fulfillment-supplies/${segments[1]}` : path,
- icon: Package
+ icon: Package,
})
-
+
if (segments[1] === 'goods' && segments[2]) {
const subcategoryMap: Record = {
- 'new': 'Новые',
- 'receiving': 'Приёмка',
- 'received': 'Принято'
+ new: 'Новые',
+ receiving: 'Приёмка',
+ received: 'Принято',
}
-
+
const subcategory = subcategoryMap[segments[2]]
if (subcategory) {
breadcrumbs.push({ name: subcategory, href: path, icon: Clock })
@@ -65,7 +74,7 @@ function Breadcrumbs({ pathname }: { pathname: string }) {
}
}
}
-
+
return breadcrumbs
}
@@ -82,10 +91,7 @@ function Breadcrumbs({ pathname }: { pathname: string }) {
{breadcrumb.name}
) : (
-
+
{breadcrumb.icon && }
{breadcrumb.name}
@@ -101,7 +107,11 @@ export function FulfillmentSuppliesLayout({ children }: { children: React.ReactN
const pathname = usePathname()
// Загружаем данные о непринятых поставках
- const { data: pendingData, error: pendingError, refetch: refetchPending } = useQuery(GET_PENDING_SUPPLIES_COUNT, {
+ const {
+ data: pendingData,
+ error: pendingError,
+ refetch: refetchPending,
+ } = useQuery(GET_PENDING_SUPPLIES_COUNT, {
fetchPolicy: 'cache-first',
errorPolicy: 'ignore',
onError: (error) => {
@@ -165,13 +175,13 @@ export function FulfillmentSuppliesLayout({ children }: { children: React.ReactN
{/* Breadcrumbs */}
-
+
{/* БЛОК 1: ТАБЫ ВСЕХ УРОВНЕЙ */}
{/* УРОВЕНЬ 1: Главные табы */}
)
-}
\ No newline at end of file
+}
diff --git a/src/components/fulfillment-supplies/fulfillment-supplies/fulfillment-detailed-supplies-tab.tsx b/src/components/fulfillment-supplies/fulfillment-supplies/fulfillment-detailed-supplies-tab.tsx
index 83c53e3..c34e914 100644
--- a/src/components/fulfillment-supplies/fulfillment-supplies/fulfillment-detailed-supplies-tab.tsx
+++ b/src/components/fulfillment-supplies/fulfillment-supplies/fulfillment-detailed-supplies-tab.tsx
@@ -1,15 +1,16 @@
'use client'
-import { useQuery } from '@apollo/client'
+import { useQuery, useMutation } from '@apollo/client'
import { TrendingUp, Wrench, Plus, Package2, Clock, CheckCircle, XCircle, Truck } from 'lucide-react'
import { useRouter } from 'next/navigation'
import React, { useState } from 'react'
+import { toast } from 'sonner'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Card } from '@/components/ui/card'
+import { FULFILLMENT_RECEIVE_CONSUMABLE_SUPPLY } from '@/graphql/mutations/fulfillment-receive-v2'
import { GET_MY_FULFILLMENT_CONSUMABLE_SUPPLIES } from '@/graphql/queries/fulfillment-consumables-v2'
-import { useAuth } from '@/hooks/useAuth'
import { StatsCard } from '../../supplies/ui/stats-card'
import { StatsGrid } from '../../supplies/ui/stats-grid'
@@ -155,7 +156,6 @@ const formatDate = (dateString: string) => {
export function FulfillmentDetailedSuppliesTab() {
const router = useRouter()
- const { user } = useAuth()
const [expandedSupplies, setExpandedSupplies] = useState
>(new Set())
// Загружаем поставки расходников через новый API v2
@@ -171,6 +171,22 @@ export function FulfillmentDetailedSuppliesTab() {
// Получаем поставки из нового API
const supplies: FulfillmentConsumableSupply[] = data?.myFulfillmentConsumableSupplies || []
+ // Мутация для приемки поставки
+ const [fulfillmentReceiveSupply] = useMutation(FULFILLMENT_RECEIVE_CONSUMABLE_SUPPLY, {
+ refetchQueries: [{ query: GET_MY_FULFILLMENT_CONSUMABLE_SUPPLIES }],
+ onCompleted: (data) => {
+ if (data.fulfillmentReceiveConsumableSupply.success) {
+ toast.success(data.fulfillmentReceiveConsumableSupply.message)
+ } else {
+ toast.error(data.fulfillmentReceiveConsumableSupply.message)
+ }
+ },
+ onError: (error) => {
+ console.error('Error receiving supply:', error)
+ toast.error('Ошибка при приемке поставки')
+ },
+ })
+
// Функция для переключения развернутого состояния поставки
const toggleExpanded = (supplyId: string) => {
const newExpanded = new Set(expandedSupplies)
@@ -182,6 +198,29 @@ export function FulfillmentDetailedSuppliesTab() {
setExpandedSupplies(newExpanded)
}
+ // Обработчик приемки поставки
+ const handleReceiveSupply = async (supply: FulfillmentConsumableSupply) => {
+ try {
+ // Создаем items для приемки (принимаем все заказанные количества без брака)
+ const items = supply.items.map((item) => ({
+ id: item.id,
+ receivedQuantity: item.requestedQuantity, // Принимаем все заказанное количество
+ defectQuantity: 0, // Без брака
+ }))
+
+ await fulfillmentReceiveSupply({
+ variables: {
+ id: supply.id,
+ items: items,
+ notes: 'Поставка принята на склад',
+ },
+ })
+ } catch (error) {
+ console.error('Error receiving supply:', error)
+ toast.error('Ошибка при приемке поставки')
+ }
+ }
+
// Вычисляем статистику
const totalSupplies = supplies.length
const totalAmount = supplies.reduce((sum, supply) => {
@@ -190,27 +229,29 @@ export function FulfillmentDetailedSuppliesTab() {
const totalItems = supplies.reduce((sum, supply) => {
return sum + supply.items.reduce((itemSum, item) => itemSum + item.requestedQuantity, 0)
}, 0)
- const deliveredCount = supplies.filter(supply => supply.status === 'DELIVERED').length
+ const deliveredCount = supplies.filter((supply) => supply.status === 'DELIVERED').length
if (loading) {
return (
-
-
-
Загрузка расходников фулфилмента...
+
+
+
+
Загрузка расходников фулфилмента...
+
)
}
if (error) {
return (
-
+
Ошибка загрузки расходников
{error.message}
-
@@ -293,17 +334,29 @@ export function FulfillmentDetailedSuppliesTab() {
{supplies.map((supply) => (
{/* Основная информация о поставке */}
- toggleExpanded(supply.id)}
>
-
- Поставка #{supply.id.slice(-8)}
-
+
Поставка #{supply.id.slice(-8)}
{getStatusBadge(supply.status)}
+ {/* Кнопка приемки для статуса SHIPPED */}
+ {supply.status === 'SHIPPED' && (
+
{
+ e.stopPropagation()
+ handleReceiveSupply(supply)
+ }}
+ className="bg-green-500/20 hover:bg-green-500/30 text-green-300 border border-green-500/30"
+ >
+
+ Принять на склад
+
+ )}
@@ -327,9 +380,11 @@ export function FulfillmentDetailedSuppliesTab() {
-
+
@@ -357,7 +412,8 @@ export function FulfillmentDetailedSuppliesTab() {
Количество: {item.requestedQuantity}
- {formatCurrency(item.unitPrice)} × {item.requestedQuantity} = {formatCurrency(item.totalPrice)}
+ {formatCurrency(item.unitPrice)} × {item.requestedQuantity} ={' '}
+ {formatCurrency(item.totalPrice)}
@@ -399,4 +455,4 @@ export function FulfillmentDetailedSuppliesTab() {
)}
)
-}
\ No newline at end of file
+}