From 74fb07155253c76ac4458b7364a8a3d3af9b7eb6 Mon Sep 17 00:00:00 2001 From: Bivekich Date: Thu, 24 Jul 2025 14:20:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=20CreateConsumablesSupplyPage:=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=83=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=BE=D0=BA=20=D1=81=D0=B5?= =?UTF-8?q?=D0=BB=D0=BB=D0=B5=D1=80=D0=B0.=20=D0=92=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D0=B5=20FulfillmentSupplie?= =?UTF-8?q?sTab=20=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=20=D0=B8?= =?UTF-8?q?=D0=BC=D0=BF=D0=BE=D1=80=D1=82=20=D0=B8=20=D0=B8=D1=81=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B2=D0=BA=D0=BB=D0=B0=D0=B4=D0=BA=D0=B8=20=D0=BD=D0=B0=20Rea?= =?UTF-8?q?lSupplyOrdersTab=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20Fulfi?= =?UTF-8?q?llmentSuppliesSubTab=20=D0=B4=D0=BB=D1=8F=20=D1=83=D0=BB=D1=83?= =?UTF-8?q?=D1=87=D1=88=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=84=D1=83=D0=BD=D0=BA?= =?UTF-8?q?=D1=86=D0=B8=D0=BE=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../create-consumables-supply-page.tsx | 4 +- .../fulfillment-supplies-tab.tsx | 4 +- .../real-supply-orders-tab.tsx | 376 ++++++++++++++++++ 3 files changed, 380 insertions(+), 4 deletions(-) create mode 100644 src/components/supplies/fulfillment-supplies/real-supply-orders-tab.tsx diff --git a/src/components/supplies/create-consumables-supply-page.tsx b/src/components/supplies/create-consumables-supply-page.tsx index 037f85f..26ecbcb 100644 --- a/src/components/supplies/create-consumables-supply-page.tsx +++ b/src/components/supplies/create-consumables-supply-page.tsx @@ -256,8 +256,8 @@ export function CreateConsumablesSupplyPage() { setProductSearchQuery(""); setSearchQuery(""); - // Перенаправляем на страницу поставок фулфилмента - router.push("/fulfillment-supplies"); + // Перенаправляем на страницу поставок селлера + router.push("/supplies"); } else { toast.error( result.data?.createSupplyOrder?.message || diff --git a/src/components/supplies/fulfillment-supplies/fulfillment-supplies-tab.tsx b/src/components/supplies/fulfillment-supplies/fulfillment-supplies-tab.tsx index 354d4fe..5bcebc2 100644 --- a/src/components/supplies/fulfillment-supplies/fulfillment-supplies-tab.tsx +++ b/src/components/supplies/fulfillment-supplies/fulfillment-supplies-tab.tsx @@ -3,7 +3,7 @@ import React, { useState } from "react"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { FulfillmentGoodsTab } from "./fulfillment-goods-tab"; -import { FulfillmentSuppliesTab as FulfillmentSuppliesSubTab } from "./fulfillment-supplies-sub-tab"; +import { RealSupplyOrdersTab } from "./real-supply-orders-tab"; import { PvzReturnsTab } from "./pvz-returns-tab"; export function FulfillmentSuppliesTab() { @@ -43,7 +43,7 @@ export function FulfillmentSuppliesTab() { - + diff --git a/src/components/supplies/fulfillment-supplies/real-supply-orders-tab.tsx b/src/components/supplies/fulfillment-supplies/real-supply-orders-tab.tsx new file mode 100644 index 0000000..e03e91f --- /dev/null +++ b/src/components/supplies/fulfillment-supplies/real-supply-orders-tab.tsx @@ -0,0 +1,376 @@ +"use client"; + +import React, { useState } from "react"; +import { Card } from "@/components/ui/card"; +import { Badge } from "@/components/ui/badge"; +import { StatsCard } from "../ui/stats-card"; +import { StatsGrid } from "../ui/stats-grid"; +import { useQuery } from "@apollo/client"; +import { GET_SUPPLY_ORDERS } from "@/graphql/queries"; +import { + Calendar, + MapPin, + Building2, + TrendingUp, + DollarSign, + Wrench, + Package2, + ChevronDown, + ChevronRight, +} from "lucide-react"; + +interface SupplyOrderItem { + id: string; + quantity: number; + price: number; + totalPrice: number; + product: { + id: string; + name: string; + article: string; + description?: string; + category?: { + id: string; + name: string; + }; + }; +} + +interface SupplyOrder { + id: string; + deliveryDate: string; + status: string; + totalAmount: number; + totalItems: number; + createdAt: string; + updatedAt: string; + partner: { + id: string; + name?: string; + fullName?: string; + inn: string; + address?: string; + phones?: string[]; + emails?: string[]; + }; + organization: { + id: string; + name?: string; + fullName?: string; + type: string; + }; + items: SupplyOrderItem[]; +} + +export function RealSupplyOrdersTab() { + const [expandedOrders, setExpandedOrders] = useState>(new Set()); + + const { data, loading, error } = useQuery(GET_SUPPLY_ORDERS); + + const supplyOrders: SupplyOrder[] = data?.supplyOrders || []; + + const toggleOrderExpansion = (orderId: string) => { + const newExpanded = new Set(expandedOrders); + if (newExpanded.has(orderId)) { + newExpanded.delete(orderId); + } else { + newExpanded.add(orderId); + } + setExpandedOrders(newExpanded); + }; + + const getStatusBadge = (status: string) => { + const statusMap: Record = { + CREATED: { + label: "Создан", + color: "bg-blue-500/20 text-blue-300 border-blue-500/30", + }, + CONFIRMED: { + label: "Подтвержден", + color: "bg-green-500/20 text-green-300 border-green-500/30", + }, + IN_PROGRESS: { + label: "В процессе", + color: "bg-yellow-500/20 text-yellow-300 border-yellow-500/30", + }, + DELIVERED: { + label: "Доставлен", + color: "bg-purple-500/20 text-purple-300 border-purple-500/30", + }, + CANCELLED: { + label: "Отменен", + color: "bg-red-500/20 text-red-300 border-red-500/30", + }, + }; + + const { label, color } = statusMap[status] || { + label: status, + color: "bg-gray-500/20 text-gray-300 border-gray-500/30", + }; + + return {label}; + }; + + const formatCurrency = (amount: number) => { + return new Intl.NumberFormat("ru-RU", { + style: "currency", + currency: "RUB", + minimumFractionDigits: 0, + }).format(amount); + }; + + const formatDate = (dateString: string) => { + return new Date(dateString).toLocaleDateString("ru-RU", { + day: "2-digit", + month: "2-digit", + year: "numeric", + }); + }; + + const formatDateTime = (dateString: string) => { + return new Date(dateString).toLocaleString("ru-RU", { + day: "2-digit", + month: "2-digit", + year: "numeric", + hour: "2-digit", + minute: "2-digit", + }); + }; + + // Статистика + const totalOrders = supplyOrders.length; + const totalAmount = supplyOrders.reduce((sum, order) => sum + order.totalAmount, 0); + const totalItems = supplyOrders.reduce((sum, order) => sum + order.totalItems, 0); + const completedOrders = supplyOrders.filter(order => order.status === "DELIVERED").length; + + if (loading) { + return ( +
+
+ Загрузка заказов расходников... +
+ ); + } + + if (error) { + return ( +
+
+ +

Ошибка загрузки заказов

+

{error.message}

+
+
+ ); + } + + return ( +
+ {/* Статистика заказов расходников */} + + + + + + + + + + + {/* Список заказов расходников */} + {supplyOrders.length === 0 ? ( + +
+ +

+ Пока нет заказов расходников +

+

+ Создайте первый заказ расходников через кнопку "Создать поставку" +

+
+
+ ) : ( + +
+ + + + + + + + + + + + + + {supplyOrders.map((order) => { + const isOrderExpanded = expandedOrders.has(order.id); + + return ( + + {/* Основная строка заказа */} + toggleOrderExpansion(order.id)} + > + + + + + + + + + + {/* Развернутая информация о заказе */} + {isOrderExpanded && ( + + + + )} + + ); + })} + +
ID + Поставщик + + Дата поставки + + Дата создания + + Количество + + Сумма + + Статус +
+
+ {isOrderExpanded ? ( + + ) : ( + + )} + + {order.id.slice(-8)} + +
+
+
+
+ + + {order.partner.name || order.partner.fullName || "Поставщик"} + +
+

+ ИНН: {order.partner.inn} +

+
+
+
+ + + {formatDate(order.deliveryDate)} + +
+
+ + {formatDateTime(order.createdAt)} + + + + {order.totalItems} шт + + +
+ + + {formatCurrency(order.totalAmount)} + +
+
{getStatusBadge(order.status)}
+
+
+

+ Состав заказа: +

+
+ {order.items.map((item) => ( + +
+
+
+ {item.product.name} +
+

+ Артикул: {item.product.article} +

+ {item.product.category && ( + + {item.product.category.name} + + )} +
+
+
+

+ Количество: {item.quantity} шт +

+

+ Цена: {formatCurrency(item.price)} +

+
+
+

+ {formatCurrency(item.totalPrice)} +

+
+
+
+
+ ))} +
+
+
+
+
+
+ )} +
+ ); +} \ No newline at end of file