+ {/* Уведомляющий баннер */}
+ {hasPendingItems && (
+
+
+
+ У вас есть {pendingCount.total} элемент{pendingCount.total > 1 ? (pendingCount.total < 5 ? 'а' : 'ов') : ''}, требующ{pendingCount.total > 1 ? 'их' : 'ий'} одобрения:
+ {pendingCount.supplyOrders > 0 && ` ${pendingCount.supplyOrders} заказ${pendingCount.supplyOrders > 1 ? (pendingCount.supplyOrders < 5 ? 'а' : 'ов') : ''} поставок`}
+ {pendingCount.incomingRequests > 0 && pendingCount.supplyOrders > 0 && ', '}
+ {pendingCount.incomingRequests > 0 && ` ${pendingCount.incomingRequests} заявк${pendingCount.incomingRequests > 1 ? (pendingCount.incomingRequests < 5 ? 'и' : '') : 'а'} на партнерство`}
+
+
+ )}
+
{/* Главные вкладки с кнопкой создания */}
-
+
0 ? 'animate-pulse' : ''}`}
>
Поставки на ФФ
ФФ
+ {pendingCount?.supplyOrders > 0 && (
+
+ {pendingCount.supplyOrders}
+
+ )}
diff --git a/src/graphql/queries.ts b/src/graphql/queries.ts
index a33eac1..e4ef1bc 100644
--- a/src/graphql/queries.ts
+++ b/src/graphql/queries.ts
@@ -836,4 +836,14 @@ export const GET_SUPPLY_ORDERS = gql`
}
}
}
+`;
+
+export const GET_PENDING_SUPPLIES_COUNT = gql`
+ query GetPendingSuppliesCount {
+ pendingSuppliesCount {
+ supplyOrders
+ incomingRequests
+ total
+ }
+ }
`;
\ No newline at end of file
diff --git a/src/graphql/resolvers.ts b/src/graphql/resolvers.ts
index 374d151..e25bb4c 100644
--- a/src/graphql/resolvers.ts
+++ b/src/graphql/resolvers.ts
@@ -772,6 +772,49 @@ export const resolvers = {
});
},
+ // Счетчик поставок, требующих одобрения
+ pendingSuppliesCount: async (_: unknown, __: unknown, context: Context) => {
+ if (!context.user) {
+ throw new GraphQLError("Требуется авторизация", {
+ extensions: { code: "UNAUTHENTICATED" },
+ });
+ }
+
+ const currentUser = await prisma.user.findUnique({
+ where: { id: context.user.id },
+ include: { organization: true },
+ });
+
+ if (!currentUser?.organization) {
+ throw new GraphQLError("У пользователя нет организации");
+ }
+
+ // Считаем заказы поставок со статусом PENDING где мы поставщики или получатели
+ const pendingSupplyOrders = await prisma.supplyOrder.count({
+ where: {
+ status: "PENDING",
+ OR: [
+ { partnerId: currentUser.organization.id }, // Заказы где мы - поставщик (нужно подтвердить)
+ { fulfillmentCenterId: currentUser.organization.id }, // Заказы где мы - получатель ФФ (нужно подтвердить)
+ ],
+ },
+ });
+
+ // Считаем входящие заявки на партнерство со статусом PENDING
+ const pendingIncomingRequests = await prisma.counterpartyRequest.count({
+ where: {
+ receiverId: currentUser.organization.id,
+ status: "PENDING",
+ },
+ });
+
+ return {
+ supplyOrders: pendingSupplyOrders,
+ incomingRequests: pendingIncomingRequests,
+ total: pendingSupplyOrders + pendingIncomingRequests,
+ };
+ },
+
// Логистика организации
myLogistics: async (_: unknown, __: unknown, context: Context) => {
if (!context.user) {
diff --git a/src/graphql/typedefs.ts b/src/graphql/typedefs.ts
index 0b5e2d4..0411bc1 100644
--- a/src/graphql/typedefs.ts
+++ b/src/graphql/typedefs.ts
@@ -43,6 +43,9 @@ export const typeDefs = gql`
# Заказы поставок расходников
supplyOrders: [SupplyOrder!]!
+ # Счетчик поставок, требующих одобрения
+ pendingSuppliesCount: PendingSuppliesCount!
+
# Логистика организации
myLogistics: [Logistics!]!
@@ -579,6 +582,12 @@ export const typeDefs = gql`
quantity: Int!
}
+ type PendingSuppliesCount {
+ supplyOrders: Int!
+ incomingRequests: Int!
+ total: Int!
+ }
+
type SupplyOrderProcessInfo {
role: String! # Роль организации в процессе (SELLER, FULFILLMENT, LOGIST)
supplier: String! # Название поставщика