feat(dashboard): supporting schema, seed, catalog links, funnel/PM labels and API contract (merge resolution)
This commit is contained in:
@@ -101,6 +101,7 @@ export function MobileTabBar() {
|
||||
if (pathname === "/wizard" || pathname.startsWith("/review")) return null;
|
||||
const onOfficePage =
|
||||
pathname === "/" ||
|
||||
pathname === "/dashboard" ||
|
||||
pathname === "/projects" ||
|
||||
pathname === "/units" ||
|
||||
pathname.startsWith("/suppliers");
|
||||
|
||||
+47
-6
@@ -19,23 +19,39 @@ import { useAuthStore } from "../store/auth";
|
||||
import type {
|
||||
Attachment,
|
||||
ConfirmedReceipt,
|
||||
DashboardFilterOptions,
|
||||
DailyControlData,
|
||||
DeadStockItem,
|
||||
DrilldownData,
|
||||
FlowDay,
|
||||
InTransitRow,
|
||||
InventoryRow,
|
||||
InventoryTransaction,
|
||||
Material,
|
||||
PendingArrival,
|
||||
Project,
|
||||
Quote,
|
||||
QuoteStats,
|
||||
StandardConversion,
|
||||
Store,
|
||||
Supplier,
|
||||
TransactionType,
|
||||
Warehouse,
|
||||
ProjectTransfer,
|
||||
ProjectTransferCreateIn,
|
||||
ProjectTransferUpdateIn,
|
||||
ProjectTransferReceiveIn,
|
||||
ProjectTransferUpdateIn,
|
||||
TransactionType,
|
||||
Warehouse,
|
||||
WorkloadProject,
|
||||
} from "./types";
|
||||
|
||||
// پارامترهای مشترک فیلتر «چه چیزی» برای endpointهای داشبورد
|
||||
// (type alias — نه interface — تا به Record<string, unknown> قابل انتساب باشد)
|
||||
export type DashboardFilterParams = {
|
||||
category_id?: string | null;
|
||||
material_id?: string | null;
|
||||
brand_id?: string | null;
|
||||
specs_hash?: string | null;
|
||||
};
|
||||
|
||||
const BASE_URL = (import.meta.env?.VITE_API_BASE_URL as string | undefined)?.trim() || "/api/v1";
|
||||
const PAGE_SIZE = 100;
|
||||
|
||||
@@ -1887,8 +1903,12 @@ export const apiV26 = {
|
||||
|
||||
pm: {
|
||||
// پروژه فعال بهصورت صریح ارسال میشود؛ بکاند تعلق آن به PM را بررسی میکند
|
||||
onTheWay: async (projectId?: string | null): Promise<PendingArrival[]> =>
|
||||
getData<PendingArrival[]>(projectId ? `/pm/on-the-way?project_id=${projectId}` : "/pm/on-the-way"),
|
||||
onTheWay: async (projectId?: string | null, params: { material_id?: string | null; brand_id?: string | null } = {}): Promise<InTransitRow[]> => {
|
||||
const qs = new URLSearchParams(
|
||||
cleanParams({ project_id: projectId ?? activeProjectId(), ...params }),
|
||||
).toString();
|
||||
return getData<InTransitRow[]>(`/pm/on-the-way${qs ? `?${qs}` : ""}`);
|
||||
},
|
||||
confirmReceipt: async (body: {
|
||||
item_decision_id: string; received_qty: number;
|
||||
allocations: { warehouse_id: string; quantity: number }[];
|
||||
@@ -1899,6 +1919,27 @@ export const apiV26 = {
|
||||
getData<ConfirmedReceipt[]>(projectId ? `/pm/receipts?project_id=${projectId}` : "/pm/receipts"),
|
||||
},
|
||||
|
||||
// ---------- داشبورد MVP (v2.8) — تجمیعهای سمت سرور، فقطخواندنی ----------
|
||||
// نقش/پروژه سمت بکاند از JWT (یا هدرهای dev) حل میشود؛ PM به پروژههای
|
||||
// خودش محدود است و ادمین/مدیر تدارکات کل سازمان را میبیند.
|
||||
dashboard: {
|
||||
filters: async (): Promise<DashboardFilterOptions> =>
|
||||
getData<DashboardFilterOptions>("/dashboard/filters"),
|
||||
drilldown: async (params: DashboardFilterParams = {}): Promise<DrilldownData> =>
|
||||
getData<DrilldownData>(`/dashboard/inventory/drilldown?${new URLSearchParams(cleanParams(params))}`),
|
||||
deadStock: async (params: DashboardFilterParams & { idle_days?: number } = {}): Promise<{ idle_days_threshold: number; items: DeadStockItem[] }> =>
|
||||
getData<{ idle_days_threshold: number; items: DeadStockItem[] }>(`/dashboard/inventory/dead-stock?${new URLSearchParams(cleanParams(params))}`),
|
||||
flow: async (params: DashboardFilterParams & { date_from?: string; date_to?: string; warehouse_id?: string } = {}): Promise<{ opening_balance: number; days: FlowDay[] }> =>
|
||||
getData<{ opening_balance: number; days: FlowDay[] }>(`/dashboard/inventory/flow?${new URLSearchParams(cleanParams(params))}`),
|
||||
dailyControl: async (params: { date?: string; warehouse_id?: string } = {}): Promise<DailyControlData> =>
|
||||
getData<DailyControlData>(`/dashboard/daily-control?${new URLSearchParams(cleanParams(params))}`),
|
||||
workload: async (): Promise<{ projects: WorkloadProject[] }> =>
|
||||
getData<{ projects: WorkloadProject[] }>("/dashboard/procurement/workload"),
|
||||
// KPI زمان تأمین + قیف تدارکات (endpoint آماری موجود /quotes/stats)
|
||||
quoteStats: async (): Promise<QuoteStats> =>
|
||||
getData<QuoteStats>("/quotes/stats"),
|
||||
},
|
||||
|
||||
// ساخت موجودیتهای کاتالوگ سراسری از داخل پنل انبار (موجودی اولیه):
|
||||
// متریال/برند/واحد جدید بدون وابستگی به دفتر تدارکات ساخته میشوند.
|
||||
catalog: {
|
||||
|
||||
+132
-1
@@ -195,6 +195,12 @@ export interface PendingArrival {
|
||||
state: "on_the_way" | "partially_received" | "arrived";
|
||||
}
|
||||
|
||||
// v2.6.1 — برند/مشخصههای فrozen قلم (اضافهشده به /pm/on-the-way برای داشبورد)
|
||||
export interface InTransitRow extends PendingArrival {
|
||||
brand: { id: string; name: string } | null;
|
||||
specs: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface ConfirmedReceipt {
|
||||
receipt_id: string;
|
||||
quote_id: string;
|
||||
@@ -208,6 +214,132 @@ export interface ConfirmedReceipt {
|
||||
allocations: { warehouse_id: string; warehouse_name: string; quantity: string }[];
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// v2.8 — داشبورد MVP (انبار + بازرگانی)
|
||||
// ============================================================
|
||||
|
||||
// — فیلتر سراسری «چه چیزی» —
|
||||
export interface FilterSpecOption {
|
||||
hash: string;
|
||||
specs: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface FilterMaterialOption {
|
||||
id: string;
|
||||
name: string;
|
||||
unit: { id: number; code: string; name_fa: string | null } | null;
|
||||
brands: { id: string; name: string }[];
|
||||
specs: FilterSpecOption[];
|
||||
}
|
||||
|
||||
export interface FilterCategoryOption {
|
||||
id: string | null; // null = «بدون دسته»
|
||||
name: string;
|
||||
slug: string | null;
|
||||
materials: FilterMaterialOption[];
|
||||
}
|
||||
|
||||
export interface DashboardFilterOptions {
|
||||
categories: FilterCategoryOption[];
|
||||
}
|
||||
|
||||
// — ماتریس Drill-Down (کل سازمان → پروژه → انبار) —
|
||||
export type QtyByUnit = Record<string, number>;
|
||||
|
||||
export interface DrilldownWarehouse {
|
||||
id: string;
|
||||
name: string;
|
||||
qty_by_unit: QtyByUnit;
|
||||
rows: number;
|
||||
}
|
||||
|
||||
export interface DrilldownProject {
|
||||
id: string;
|
||||
name: string;
|
||||
qty_by_unit: QtyByUnit;
|
||||
rows: number;
|
||||
warehouses: DrilldownWarehouse[];
|
||||
}
|
||||
|
||||
export interface DrilldownData {
|
||||
units: Record<string, string>;
|
||||
total: { qty_by_unit: QtyByUnit; rows: number };
|
||||
projects: DrilldownProject[];
|
||||
}
|
||||
|
||||
// — جدول موجودی راکد —
|
||||
export interface DeadStockItem {
|
||||
inventory_id: string;
|
||||
material: string;
|
||||
brand: string | null;
|
||||
specs: Record<string, string>;
|
||||
warehouse: string;
|
||||
project: string;
|
||||
quantity: number;
|
||||
unit: { code: string; name_fa: string | null };
|
||||
last_activity: string | null;
|
||||
idle_days: number | null;
|
||||
}
|
||||
|
||||
// — سری زمانی جریان روزانه —
|
||||
export interface FlowDay {
|
||||
date: string; // ISO (YYYY-MM-DD)
|
||||
inbound: number;
|
||||
outbound: number;
|
||||
waste: number;
|
||||
returns: number;
|
||||
balance: number;
|
||||
}
|
||||
|
||||
// — کنترل روزانه —
|
||||
export interface DailyControlData {
|
||||
date: string;
|
||||
outbound: { tickets: number; qty: number };
|
||||
returns: { tickets: number; qty: number };
|
||||
waste: { tickets: number; qty: number };
|
||||
purchases: { tickets: number; qty: number };
|
||||
performers: { name: string; tickets: number; qty: number }[];
|
||||
items: {
|
||||
id: string;
|
||||
transaction_type: string;
|
||||
quantity: number;
|
||||
unit_code: string;
|
||||
performed_by: string | null;
|
||||
note: string | null;
|
||||
warehouse: string;
|
||||
material: string;
|
||||
specs: Record<string, string>;
|
||||
transaction_date: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
// — بازرگانی: قیف تدارکات + KPI زمان تأمین (/quotes/stats) —
|
||||
export interface QuoteStats {
|
||||
total: number;
|
||||
offered: number;
|
||||
accepted: number;
|
||||
arrived: number;
|
||||
rejected: number;
|
||||
expired: number;
|
||||
average_lead_time_days: number | null;
|
||||
funnel: {
|
||||
offered_total: number;
|
||||
accepted_total: number;
|
||||
arrived_total: number;
|
||||
};
|
||||
}
|
||||
|
||||
// — بار تدارکات روی پروژهها (Project Density) —
|
||||
export interface WorkloadProject {
|
||||
id: string | null;
|
||||
name: string;
|
||||
offered_quotes: number;
|
||||
chosen_items: number;
|
||||
open_orders: number;
|
||||
ordered_qty: number;
|
||||
received_qty: number;
|
||||
}
|
||||
|
||||
export interface ProjectTransfer {
|
||||
id: string;
|
||||
from_project: { id: string; name: string };
|
||||
@@ -255,4 +387,3 @@ export interface ProjectTransferReceiveIn {
|
||||
received_at?: string | null;
|
||||
note?: string | null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Users, FolderKanban, Ruler, Plus } from "lucide-react";
|
||||
import { Users, FolderKanban, Ruler, Plus, ChartColumnBig } from "lucide-react";
|
||||
import {
|
||||
useMaterials,
|
||||
useProjects,
|
||||
@@ -94,6 +94,15 @@ export function DashboardPage() {
|
||||
menu={<AppSwitcherMenu activeModule="procurement" />}
|
||||
actions={
|
||||
<div className="hidden md:flex items-center gap-2">
|
||||
{/* داشبورد تحلیلی — دکمهی مستقل، همسبک با «پروژهها» و «ضرایب تبدیل» */}
|
||||
<Link
|
||||
to="/dashboard"
|
||||
className="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-xl border border-gray-200 dark:border-zinc-700 bg-white dark:bg-zinc-800 text-gray-700 dark:text-zinc-200 text-xs font-semibold hover:bg-gray-50 dark:hover:bg-zinc-700 shadow-2xs transition-all no-underline"
|
||||
>
|
||||
<ChartColumnBig className="h-4 w-4 text-gray-500 dark:text-zinc-400" />
|
||||
<span>داشبورد</span>
|
||||
</Link>
|
||||
|
||||
<Link to="/suppliers" className="btn-line-file no-underline">
|
||||
<Users className="h-3.5 w-3.5" />
|
||||
تأمینکنندهها
|
||||
|
||||
Reference in New Issue
Block a user