Refactor: Replace wholesaler with supplier terminology and add fulfillment consumables logic

This commit is contained in:
Veronika Smirnova
2025-07-30 17:03:31 +03:00
parent e351752b09
commit 3e7ea13026
31 changed files with 3343 additions and 1538 deletions

View File

@ -4,7 +4,7 @@ import React, { useState, useMemo, useCallback } from "react";
import { Sidebar } from "@/components/dashboard/sidebar";
import { useSidebar } from "@/hooks/useSidebar";
import { useQuery } from "@apollo/client";
import { GET_MY_SUPPLIES } from "@/graphql/queries";
import { GET_MY_FULFILLMENT_SUPPLIES } from "@/graphql/queries";
import {
Package,
Wrench,
@ -87,14 +87,14 @@ export function FulfillmentSuppliesPage() {
loading,
error,
refetch,
} = useQuery(GET_MY_SUPPLIES, {
} = useQuery(GET_MY_FULFILLMENT_SUPPLIES, {
fetchPolicy: "cache-and-network",
onError: (error) => {
toast.error("Ошибка загрузки расходников: " + error.message);
toast.error("Ошибка загрузки расходников фулфилмента: " + error.message);
},
});
const supplies: Supply[] = suppliesData?.mySupplies || [];
const supplies: Supply[] = suppliesData?.myFulfillmentSupplies || [];
// Логирование для отладки
console.log("🔥🔥🔥 FULFILLMENT SUPPLIES PAGE DATA 🔥🔥🔥", {
@ -142,17 +142,17 @@ export function FulfillmentSuppliesPage() {
// Суммируем поставленное количество (заказано = поставлено)
acc[key].quantity += supply.quantity;
// Суммируем отправленное количество
acc[key].shippedQuantity += supply.shippedQuantity || 0;
// Остаток = Поставлено - Отправлено
// Если ничего не отправлено, то остаток = поставлено
acc[key].currentStock = acc[key].quantity - acc[key].shippedQuantity;
// Рассчитываем общую стоимость (количество × цена)
acc[key].totalCost += supply.quantity * supply.price;
// Средневзвешенная цена за единицу
if (acc[key].quantity > 0) {
acc[key].price = acc[key].totalCost / acc[key].quantity;
@ -265,7 +265,7 @@ export function FulfillmentSuppliesPage() {
const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = `расходники_фф_${
link.download = `расходники_фулфилмента_${
new Date().toISOString().split("T")[0]
}.csv`;
link.click();