Add new api for stats in process innovation page, also fix some style
This commit is contained in:
parent
679f2b5d3a
commit
ccf1139fe6
|
|
@ -22,10 +22,6 @@ import {
|
||||||
ChevronUp,
|
ChevronUp,
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
RefreshCw,
|
RefreshCw,
|
||||||
TrendingUp,
|
|
||||||
TrendingDown,
|
|
||||||
Target,
|
|
||||||
BarChart3,
|
|
||||||
ExternalLink,
|
ExternalLink,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import apiService from "~/lib/api";
|
import apiService from "~/lib/api";
|
||||||
|
|
@ -57,6 +53,19 @@ interface StatsCard {
|
||||||
color: string;
|
color: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface InnovationStats {
|
||||||
|
totalProjects: number;
|
||||||
|
averageScore: number;
|
||||||
|
productionStopsPreventionSum: number; // مجموع جلوگیری از توقفات تولید
|
||||||
|
bottleneckRemovalCount: number; // تعداد رفع گلوگاه
|
||||||
|
currencyReductionSum: number; // مجموع کاهش ارز بری (میلیون ریال)
|
||||||
|
frequentFailuresReductionSum: number; // مجموع کاهش خرابی های پرتکرار
|
||||||
|
percentProductionStops: number; // درصد مقایسهای جلوگیری از توقفات تولید
|
||||||
|
percentBottleneckRemoval: number; // درصد مقایسهای رفع گلوگاه
|
||||||
|
percentCurrencyReduction: number; // درصد مقایسهای کاهش ارز بری
|
||||||
|
percentFailuresReduction: number; // درصد مقایسهای کاهش خرابیهای پرتکرار
|
||||||
|
}
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{ key: "select", label: "", sortable: false, width: "50px" },
|
{ key: "select", label: "", sortable: false, width: "50px" },
|
||||||
{ key: "project_no", label: "شماره پروژه", sortable: true, width: "140px" },
|
{ key: "project_no", label: "شماره پروژه", sortable: true, width: "140px" },
|
||||||
|
|
@ -75,6 +84,19 @@ export function ProcessInnovationPage() {
|
||||||
const [hasMore, setHasMore] = useState(true);
|
const [hasMore, setHasMore] = useState(true);
|
||||||
const [totalCount, setTotalCount] = useState(0);
|
const [totalCount, setTotalCount] = useState(0);
|
||||||
const [actualTotalCount, setActualTotalCount] = useState(0);
|
const [actualTotalCount, setActualTotalCount] = useState(0);
|
||||||
|
const [statsLoading, setStatsLoading] = useState(false);
|
||||||
|
const [stats, setStats] = useState<InnovationStats>({
|
||||||
|
totalProjects: 0,
|
||||||
|
averageScore: 0,
|
||||||
|
productionStopsPreventionSum: 0,
|
||||||
|
bottleneckRemovalCount: 0,
|
||||||
|
currencyReductionSum: 0,
|
||||||
|
frequentFailuresReductionSum: 0,
|
||||||
|
percentProductionStops: 0,
|
||||||
|
percentBottleneckRemoval: 0,
|
||||||
|
percentCurrencyReduction: 0,
|
||||||
|
percentFailuresReduction: 0,
|
||||||
|
});
|
||||||
const [sortConfig, setSortConfig] = useState<SortConfig>({
|
const [sortConfig, setSortConfig] = useState<SortConfig>({
|
||||||
field: "start_date",
|
field: "start_date",
|
||||||
direction: "asc",
|
direction: "asc",
|
||||||
|
|
@ -121,10 +143,7 @@ export function ProcessInnovationPage() {
|
||||||
{
|
{
|
||||||
id: "production-stops-prevention",
|
id: "production-stops-prevention",
|
||||||
title: "جلوگیری از توقفات تولید",
|
title: "جلوگیری از توقفات تولید",
|
||||||
value: formatNumber(projects
|
value: formatNumber(stats.productionStopsPreventionSum.toFixed?.(1) ?? stats.productionStopsPreventionSum),
|
||||||
.filter(p => p.reduce_prevention_production_stops && parseFloat(p.reduce_prevention_production_stops) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.reduce_prevention_production_stops), 0)
|
|
||||||
.toFixed(1)),
|
|
||||||
description: "ظرفیت افزایش یافته",
|
description: "ظرفیت افزایش یافته",
|
||||||
icon: <CirclePause/>,
|
icon: <CirclePause/>,
|
||||||
color: "text-emerald-400",
|
color: "text-emerald-400",
|
||||||
|
|
@ -132,7 +151,7 @@ export function ProcessInnovationPage() {
|
||||||
{
|
{
|
||||||
id: "bottleneck-removal",
|
id: "bottleneck-removal",
|
||||||
title: "رفع گلوگاه",
|
title: "رفع گلوگاه",
|
||||||
value: formatNumber(projects.filter(p => p.throat_removal === "بله").length),
|
value: formatNumber(stats.bottleneckRemovalCount),
|
||||||
description: "تعداد رفع گلوگاه",
|
description: "تعداد رفع گلوگاه",
|
||||||
icon: <Funnel />,
|
icon: <Funnel />,
|
||||||
color: "text-emerald-400"
|
color: "text-emerald-400"
|
||||||
|
|
@ -141,10 +160,7 @@ export function ProcessInnovationPage() {
|
||||||
{
|
{
|
||||||
id: "currency-reduction",
|
id: "currency-reduction",
|
||||||
title: "کاهش ارز بری",
|
title: "کاهش ارز بری",
|
||||||
value: formatNumber(projects
|
value: formatNumber(stats.currencyReductionSum.toFixed?.(0) ?? stats.currencyReductionSum),
|
||||||
.filter(p => p.amount_currency_reduction && parseFloat(p.amount_currency_reduction) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.amount_currency_reduction), 0)
|
|
||||||
.toFixed(0)),
|
|
||||||
description: "میلیون ریال کاهش یافته",
|
description: "میلیون ریال کاهش یافته",
|
||||||
icon: <DollarSign/>,
|
icon: <DollarSign/>,
|
||||||
color: "text-emerald-400",
|
color: "text-emerald-400",
|
||||||
|
|
@ -152,10 +168,7 @@ export function ProcessInnovationPage() {
|
||||||
{
|
{
|
||||||
id: "frequent-failures-reduction",
|
id: "frequent-failures-reduction",
|
||||||
title: "کاهش خرابیهای پرتکرار",
|
title: "کاهش خرابیهای پرتکرار",
|
||||||
value: formatNumber(projects
|
value: formatNumber(stats.frequentFailuresReductionSum.toFixed?.(1) ?? stats.frequentFailuresReductionSum),
|
||||||
.filter(p => p.Reduce_rate_failure && parseFloat(p.Reduce_rate_failure) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.Reduce_rate_failure), 0)
|
|
||||||
.toFixed(1)),
|
|
||||||
description: "مجموع درصد کاهش خرابی",
|
description: "مجموع درصد کاهش خرابی",
|
||||||
icon: <Wrench/>,
|
icon: <Wrench/>,
|
||||||
color: "text-emerald-400",
|
color: "text-emerald-400",
|
||||||
|
|
@ -191,6 +204,7 @@ export function ProcessInnovationPage() {
|
||||||
"amount_currency_reduction",
|
"amount_currency_reduction",
|
||||||
"Reduce_rate_failure",
|
"Reduce_rate_failure",
|
||||||
],
|
],
|
||||||
|
Pagination: { PageNumber: pageToFetch, PageSize: pageSize },
|
||||||
Sorts: [[sortConfig.field, sortConfig.direction]],
|
Sorts: [[sortConfig.field, sortConfig.direction]],
|
||||||
Conditions: [["type_of_innovation", "=", "نوآوری در فرآیند"]],
|
Conditions: [["type_of_innovation", "=", "نوآوری در فرآیند"]],
|
||||||
});
|
});
|
||||||
|
|
@ -263,6 +277,7 @@ export function ProcessInnovationPage() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchProjects(true);
|
fetchProjects(true);
|
||||||
fetchTotalCount();
|
fetchTotalCount();
|
||||||
|
fetchStats();
|
||||||
}, [sortConfig]);
|
}, [sortConfig]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -322,7 +337,10 @@ export function ProcessInnovationPage() {
|
||||||
try {
|
try {
|
||||||
const parsedData = JSON.parse(dataString);
|
const parsedData = JSON.parse(dataString);
|
||||||
if (Array.isArray(parsedData) && parsedData[0]) {
|
if (Array.isArray(parsedData) && parsedData[0]) {
|
||||||
setActualTotalCount(parsedData[0].project_no_count || 0);
|
const count = parsedData[0].project_no_count || 0;
|
||||||
|
setActualTotalCount(count);
|
||||||
|
// Keep stats in sync if backend stats not yet loaded
|
||||||
|
setStats((prev) => ({ ...prev, totalProjects: count }));
|
||||||
}
|
}
|
||||||
} catch (parseError) {
|
} catch (parseError) {
|
||||||
console.error("Error parsing count data:", parseError);
|
console.error("Error parsing count data:", parseError);
|
||||||
|
|
@ -334,6 +352,52 @@ export function ProcessInnovationPage() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Fetch aggregated stats from backend call API (innovation_process_function)
|
||||||
|
const fetchStats = async () => {
|
||||||
|
try {
|
||||||
|
setStatsLoading(true);
|
||||||
|
const raw = await apiService.callInnovationProcess<any>({
|
||||||
|
innovation_process_function: {
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
let payload: any = raw?.data;
|
||||||
|
if (typeof payload === "string") {
|
||||||
|
try { payload = JSON.parse(payload); } catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const parseNum = (v: unknown): number => {
|
||||||
|
if (v == null) return 0;
|
||||||
|
if (typeof v === "number") return v;
|
||||||
|
if (typeof v === "string") {
|
||||||
|
const cleaned = v.replace(/,/g, "").trim();
|
||||||
|
const n = parseFloat(cleaned);
|
||||||
|
return isNaN(n) ? 0 : n;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const normalized: InnovationStats = {
|
||||||
|
totalProjects: parseNum(payload?.count_innovation_process_projects),
|
||||||
|
averageScore: parseNum(payload?.average_project_score),
|
||||||
|
productionStopsPreventionSum: parseNum(payload?.sum_stopping_production),
|
||||||
|
bottleneckRemovalCount: parseNum(payload?.count_throat_removal),
|
||||||
|
currencyReductionSum: parseNum(payload?.sum_reduction_value_currency),
|
||||||
|
frequentFailuresReductionSum: parseNum(payload?.sum_reducing_breakdowns),
|
||||||
|
percentProductionStops: parseNum(payload?.percent_sum_stopping_production),
|
||||||
|
percentBottleneckRemoval: parseNum(payload?.percent_throat_removal),
|
||||||
|
percentCurrencyReduction: parseNum(payload?.percent_reduction_value_currency),
|
||||||
|
percentFailuresReduction: parseNum(payload?.percent_reducing_breakdowns),
|
||||||
|
};
|
||||||
|
|
||||||
|
setStats(normalized);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching stats:", error);
|
||||||
|
} finally {
|
||||||
|
setStatsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleRefresh = () => {
|
const handleRefresh = () => {
|
||||||
fetchingRef.current = false;
|
fetchingRef.current = false;
|
||||||
setCurrentPage(1);
|
setCurrentPage(1);
|
||||||
|
|
@ -341,6 +405,7 @@ export function ProcessInnovationPage() {
|
||||||
setHasMore(true);
|
setHasMore(true);
|
||||||
fetchProjects(true);
|
fetchProjects(true);
|
||||||
fetchTotalCount();
|
fetchTotalCount();
|
||||||
|
fetchStats();
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatCurrency = (amount: string | number) => {
|
const formatCurrency = (amount: string | number) => {
|
||||||
|
|
@ -468,13 +533,13 @@ export function ProcessInnovationPage() {
|
||||||
<div className="space-y-6 w-full">
|
<div className="space-y-6 w-full">
|
||||||
{/* Stats Grid */}
|
{/* Stats Grid */}
|
||||||
<div className="grid grid-cols-2 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
{loading ? (
|
{loading || statsLoading ? (
|
||||||
// Loading skeleton for stats cards - matching new design
|
// Loading skeleton for stats cards - matching new design
|
||||||
Array.from({ length: 4 }).map((_, index) => (
|
Array.from({ length: 4 }).map((_, index) => (
|
||||||
<Card key={`skeleton-${index}`} className="bg-[linear-gradient(to_bottom_left,#464861,50%,#111628)] backdrop-blur-sm rounded-2xl overflow-hidden">
|
<Card key={`skeleton-${index}`} className="bg-[linear-gradient(to_bottom_left,#464861,50%,#111628)] backdrop-blur-sm rounded-2xl overflow-hidden">
|
||||||
<CardContent className="p-2">
|
<CardContent className="p-2">
|
||||||
<div className="flex flex-col justify-between gap-2">
|
<div className="flex flex-col justify-between gap-2">
|
||||||
<div className="flex p-2 justify-between items-center border-b-2 mx-4 border-gray-500/20">
|
<div className="flex justify-between items-center border-b-2 mx-4 border-gray-500/20">
|
||||||
<div className="h-6 bg-gray-600 rounded animate-pulse" style={{ width: '60%' }} />
|
<div className="h-6 bg-gray-600 rounded animate-pulse" style={{ width: '60%' }} />
|
||||||
<div className="p-3 bg-emerald-500/20 rounded-full w-fit">
|
<div className="p-3 bg-emerald-500/20 rounded-full w-fit">
|
||||||
<div className="w-6 h-6 bg-gray-600 rounded animate-pulse" />
|
<div className="w-6 h-6 bg-gray-600 rounded animate-pulse" />
|
||||||
|
|
@ -493,16 +558,16 @@ export function ProcessInnovationPage() {
|
||||||
<Card key={card.id} className="bg-[linear-gradient(to_bottom_left,#464861,50%,#111628)] backdrop-blur-sm border-gray-700/50">
|
<Card key={card.id} className="bg-[linear-gradient(to_bottom_left,#464861,50%,#111628)] backdrop-blur-sm border-gray-700/50">
|
||||||
<CardContent className="p-2">
|
<CardContent className="p-2">
|
||||||
<div className="flex flex-col justify-between gap-2">
|
<div className="flex flex-col justify-between gap-2">
|
||||||
<div className="flex p-2 justify-between items-center border-b-2 mx-4 border-gray-500/20">
|
<div className="flex justify-between items-center border-b-2 mx-4 border-gray-500/20">
|
||||||
<h3 className="text-lg font-bold text-white font-persian mb-2 ">
|
<h3 className="text-lg font-bold text-white font-persian">
|
||||||
{card.title}
|
{card.title}
|
||||||
</h3>
|
</h3>
|
||||||
<div className={`p-3 ${card.bgColor} gird placeitems-center rounded-full w-fit `}>
|
<div className={`p-3 gird placeitems-center rounded-full w-fit `}>
|
||||||
{card.icon}
|
{card.icon}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center justify-center flex-col p-1">
|
<div className="flex items-center justify-center flex-col p-1">
|
||||||
<p className={`text-3xl font-bold ${card.color} mb-1`}>
|
<p className={`text-3xl font-bold ${card.color} mb-1`}>
|
||||||
{card.value}
|
{card.value}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-sm text-gray-300 font-persian">
|
<p className="text-sm text-gray-300 font-persian">
|
||||||
|
|
@ -520,8 +585,8 @@ export function ProcessInnovationPage() {
|
||||||
|
|
||||||
{/* Process Impacts Chart */}
|
{/* Process Impacts Chart */}
|
||||||
<Card className="bg-[linear-gradient(to_bottom_left,#464861,50%,#111628)] backdrop-blur-sm rounded-2xl w-full overflow-hidden">
|
<Card className="bg-[linear-gradient(to_bottom_left,#464861,50%,#111628)] backdrop-blur-sm rounded-2xl w-full overflow-hidden">
|
||||||
<CardContent className="p-6">
|
<CardContent className="p-4">
|
||||||
<div className="mb-6">
|
<div className="mb-4">
|
||||||
<h3 className="text-xl font-bold text-white font-persian text-right mb-2">
|
<h3 className="text-xl font-bold text-white font-persian text-right mb-2">
|
||||||
تاثیرات فرآیندی به صورت درصد مقایسه ای
|
تاثیرات فرآیندی به صورت درصد مقایسه ای
|
||||||
</h3>
|
</h3>
|
||||||
|
|
@ -536,21 +601,13 @@ export function ProcessInnovationPage() {
|
||||||
<div
|
<div
|
||||||
className="bg-emerald-400 h-5 rounded-full transition-all duration-500 ease-out"
|
className="bg-emerald-400 h-5 rounded-full transition-all duration-500 ease-out"
|
||||||
style={{
|
style={{
|
||||||
width: `${Math.min(
|
width: `${Math.min((stats.percentProductionStops || 0), 100)}%`
|
||||||
projects
|
|
||||||
.filter(p => p.reduce_prevention_production_stops && parseFloat(p.reduce_prevention_production_stops) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.reduce_prevention_production_stops), 0) / 10,
|
|
||||||
100
|
|
||||||
)}%`
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-emerald-400 font-bold text-sm min-w-[40px] text-left">
|
<span className="text-emerald-400 font-bold text-sm min-w-[40px] text-left">
|
||||||
{formatNumber(projects
|
{formatNumber(((stats.percentProductionStops ?? 0) as number).toFixed?.(1) ?? (stats.percentProductionStops ?? 0))}%
|
||||||
.filter(p => p.reduce_prevention_production_stops && parseFloat(p.reduce_prevention_production_stops) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.reduce_prevention_production_stops), 0)
|
|
||||||
.toFixed(1))}%
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -561,16 +618,13 @@ export function ProcessInnovationPage() {
|
||||||
<div
|
<div
|
||||||
className="bg-emerald-400 h-5 rounded-full transition-all duration-500 ease-out"
|
className="bg-emerald-400 h-5 rounded-full transition-all duration-500 ease-out"
|
||||||
style={{
|
style={{
|
||||||
width: `${Math.min(
|
width: `${Math.min((stats.percentBottleneckRemoval || 0), 100)}%`
|
||||||
projects.filter(p => p.throat_removal === "بله").length * 10,
|
|
||||||
100
|
|
||||||
)}%`
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-emerald-400 font-bold text-sm min-w-[40px] text-left">
|
<span className="text-emerald-400 font-bold text-sm min-w-[40px] text-left">
|
||||||
{formatNumber(projects.filter(p => p.throat_removal === "بله").length)}%
|
{formatNumber(((stats.percentBottleneckRemoval ?? 0) as number).toFixed?.(1) ?? (stats.percentBottleneckRemoval ?? 0))}%
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -581,21 +635,13 @@ export function ProcessInnovationPage() {
|
||||||
<div
|
<div
|
||||||
className="bg-emerald-400 h-5 rounded-full transition-all duration-500 ease-out"
|
className="bg-emerald-400 h-5 rounded-full transition-all duration-500 ease-out"
|
||||||
style={{
|
style={{
|
||||||
width: `${Math.min(
|
width: `${Math.min((stats.percentCurrencyReduction || 0), 100)}%`
|
||||||
projects
|
|
||||||
.filter(p => p.amount_currency_reduction && parseFloat(p.amount_currency_reduction) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.amount_currency_reduction), 0) / 100,
|
|
||||||
100
|
|
||||||
)}%`
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-emerald-400 font-bold text-sm min-w-[40px] text-left">
|
<span className="text-emerald-400 font-bold text-sm min-w-[40px] text-left">
|
||||||
{formatNumber(projects
|
{formatNumber(((stats.percentCurrencyReduction ?? 0) as number).toFixed?.(0) ?? (stats.percentCurrencyReduction ?? 0))}%
|
||||||
.filter(p => p.amount_currency_reduction && parseFloat(p.amount_currency_reduction) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.amount_currency_reduction), 0)
|
|
||||||
.toFixed(0))}%
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -606,21 +652,13 @@ export function ProcessInnovationPage() {
|
||||||
<div
|
<div
|
||||||
className="bg-emerald-400 h-5 rounded-full transition-all duration-500 ease-out"
|
className="bg-emerald-400 h-5 rounded-full transition-all duration-500 ease-out"
|
||||||
style={{
|
style={{
|
||||||
width: `${Math.min(
|
width: `${Math.min((stats.percentFailuresReduction || 0), 100)}%`
|
||||||
projects
|
|
||||||
.filter(p => p.Reduce_rate_failure && parseFloat(p.Reduce_rate_failure) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.Reduce_rate_failure), 0) / 10,
|
|
||||||
100
|
|
||||||
)}%`
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-emerald-400 font-bold text-sm min-w-[40px] text-left">
|
<span className="text-emerald-400 font-bold text-sm min-w-[40px] text-left">
|
||||||
{formatNumber(projects
|
{formatNumber(((stats.percentFailuresReduction ?? 0) as number).toFixed?.(1) ?? (stats.percentFailuresReduction ?? 0))}%
|
||||||
.filter(p => p.Reduce_rate_failure && parseFloat(p.Reduce_rate_failure) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.Reduce_rate_failure), 0)
|
|
||||||
.toFixed(1))}%
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -628,62 +666,23 @@ export function ProcessInnovationPage() {
|
||||||
{/* Percentage Scale */}
|
{/* Percentage Scale */}
|
||||||
<div className="flex justify-between mt-6 pt-4 border-t border-gray-700">
|
<div className="flex justify-between mt-6 pt-4 border-t border-gray-700">
|
||||||
<span className="text-gray-400 text-xs">۰٪</span>
|
<span className="text-gray-400 text-xs">۰٪</span>
|
||||||
<span className="text-gray-400 text-xs">
|
{
|
||||||
{formatNumber(Math.round(Math.max(
|
(() => {
|
||||||
projects
|
const p1 = (stats.percentProductionStops || 0);
|
||||||
.filter(p => p.reduce_prevention_production_stops && parseFloat(p.reduce_prevention_production_stops) > 0)
|
const p2 = (stats.percentBottleneckRemoval || 0);
|
||||||
.reduce((sum, p) => sum + parseFloat(p.reduce_prevention_production_stops), 0) / 10,
|
const p3 = (stats.percentCurrencyReduction || 0);
|
||||||
projects.filter(p => p.throat_removal === "بله").length * 10,
|
const p4 = (stats.percentFailuresReduction || 0);
|
||||||
projects
|
const maxVal = Math.max(p1, p2, p3, p4);
|
||||||
.filter(p => p.amount_currency_reduction && parseFloat(p.amount_currency_reduction) > 0)
|
return (
|
||||||
.reduce((sum, p) => sum + parseFloat(p.amount_currency_reduction), 0) / 100,
|
<>
|
||||||
projects
|
<span className="text-gray-400 text-xs">{formatNumber(Math.round(maxVal / 4))}٪</span>
|
||||||
.filter(p => p.Reduce_rate_failure && parseFloat(p.Reduce_rate_failure) > 0)
|
<span className="text-gray-400 text-xs">{formatNumber(Math.round(maxVal / 2))}٪</span>
|
||||||
.reduce((sum, p) => sum + parseFloat(p.Reduce_rate_failure), 0) / 10
|
<span className="text-gray-400 text-xs">{formatNumber(Math.round((maxVal * 3) / 4))}٪</span>
|
||||||
) / 4))}٪
|
<span className="text-gray-400 text-xs">{formatNumber(Math.round(maxVal))}٪</span>
|
||||||
</span>
|
</>
|
||||||
<span className="text-gray-400 text-xs">
|
);
|
||||||
{formatNumber(Math.round(Math.max(
|
})()
|
||||||
projects
|
}
|
||||||
.filter(p => p.reduce_prevention_production_stops && parseFloat(p.reduce_prevention_production_stops) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.reduce_prevention_production_stops), 0) / 10,
|
|
||||||
projects.filter(p => p.throat_removal === "بله").length * 10,
|
|
||||||
projects
|
|
||||||
.filter(p => p.amount_currency_reduction && parseFloat(p.amount_currency_reduction) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.amount_currency_reduction), 0) / 100,
|
|
||||||
projects
|
|
||||||
.filter(p => p.Reduce_rate_failure && parseFloat(p.Reduce_rate_failure) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.Reduce_rate_failure), 0) / 10
|
|
||||||
) / 2))}٪
|
|
||||||
</span>
|
|
||||||
<span className="text-gray-400 text-xs">
|
|
||||||
{formatNumber(Math.round(Math.max(
|
|
||||||
projects
|
|
||||||
.filter(p => p.reduce_prevention_production_stops && parseFloat(p.reduce_prevention_production_stops) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.reduce_prevention_production_stops), 0) / 10,
|
|
||||||
projects.filter(p => p.throat_removal === "بله").length * 10,
|
|
||||||
projects
|
|
||||||
.filter(p => p.amount_currency_reduction && parseFloat(p.amount_currency_reduction) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.amount_currency_reduction), 0) / 100,
|
|
||||||
projects
|
|
||||||
.filter(p => p.Reduce_rate_failure && parseFloat(p.Reduce_rate_failure) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.Reduce_rate_failure), 0) / 10
|
|
||||||
) * 3 / 4))}٪
|
|
||||||
</span>
|
|
||||||
<span className="text-gray-400 text-xs">
|
|
||||||
{formatNumber(Math.round(Math.max(
|
|
||||||
projects
|
|
||||||
.filter(p => p.reduce_prevention_production_stops && parseFloat(p.reduce_prevention_production_stops) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.reduce_prevention_production_stops), 0) / 10,
|
|
||||||
projects.filter(p => p.throat_removal === "بله").length * 10,
|
|
||||||
projects
|
|
||||||
.filter(p => p.amount_currency_reduction && parseFloat(p.amount_currency_reduction) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.amount_currency_reduction), 0) / 100,
|
|
||||||
projects
|
|
||||||
.filter(p => p.Reduce_rate_failure && parseFloat(p.Reduce_rate_failure) > 0)
|
|
||||||
.reduce((sum, p) => sum + parseFloat(p.Reduce_rate_failure), 0) / 10
|
|
||||||
)))}٪
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
@ -691,7 +690,7 @@ export function ProcessInnovationPage() {
|
||||||
|
|
||||||
{/* Data Table */}
|
{/* Data Table */}
|
||||||
<Card className="bg-transparent backdrop-blur-sm rounded-2xl overflow-hidden">
|
<Card className="bg-transparent backdrop-blur-sm rounded-2xl overflow-hidden">
|
||||||
<CardContent className="p-0">
|
<CardContent>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<div className="overflow-auto max-h-[calc(100vh-400px)]">
|
<div className="overflow-auto max-h-[calc(100vh-400px)]">
|
||||||
<Table>
|
<Table>
|
||||||
|
|
@ -785,7 +784,7 @@ export function ProcessInnovationPage() {
|
||||||
{/* Infinite scroll trigger */}
|
{/* Infinite scroll trigger */}
|
||||||
<div ref={observerRef} className="h-auto">
|
<div ref={observerRef} className="h-auto">
|
||||||
{loadingMore && (
|
{loadingMore && (
|
||||||
<div className="flex items-center justify-center py-4">
|
<div className="flex items-center justify-center py-1">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<RefreshCw className="w-4 h-4 animate-spin text-emerald-400" />
|
<RefreshCw className="w-4 h-4 animate-spin text-emerald-400" />
|
||||||
<span className="font-persian text-gray-300 text-xs">
|
<span className="font-persian text-gray-300 text-xs">
|
||||||
|
|
@ -823,7 +822,7 @@ export function ProcessInnovationPage() {
|
||||||
<div className="p-2 px-4 bg-gray-700/50">
|
<div className="p-2 px-4 bg-gray-700/50">
|
||||||
<div className="grid grid-cols-6 gap-4 text-sm text-gray-300 font-persian">
|
<div className="grid grid-cols-6 gap-4 text-sm text-gray-300 font-persian">
|
||||||
<div className="text-center gap-2 items-center flex">
|
<div className="text-center gap-2 items-center flex">
|
||||||
<div className="text-base text-gray-401 mb-1"> کل پروژه ها : {formatNumber(actualTotalCount)}</div>
|
<div className="text-base text-gray-401 mb-1"> کل پروژه ها : {formatNumber(stats.totalProjects || actualTotalCount)}</div>
|
||||||
</div>
|
</div>
|
||||||
{/* Project number column - empty */}
|
{/* Project number column - empty */}
|
||||||
<div></div>
|
<div></div>
|
||||||
|
|
@ -835,13 +834,7 @@ export function ProcessInnovationPage() {
|
||||||
<div className="flex justify-center items-center gap-2">
|
<div className="flex justify-center items-center gap-2">
|
||||||
<div className="text-base text-gray-400 mb-1"> میانگین امتیاز :</div>
|
<div className="text-base text-gray-400 mb-1"> میانگین امتیاز :</div>
|
||||||
<div className="font-bold">
|
<div className="font-bold">
|
||||||
{(() => {
|
{formatNumber(((stats.averageScore ?? 0) as number).toFixed?.(1) ?? (stats.averageScore ?? 0))}
|
||||||
if (projects.length === 0) return formatNumber(0);
|
|
||||||
const validRatings = projects.filter(p => p.project_rating && !isNaN(parseFloat(p.project_rating)));
|
|
||||||
if (validRatings.length === 0) return formatNumber(0);
|
|
||||||
const average = validRatings.reduce((sum, p) => sum + parseFloat(p.project_rating), 0) / validRatings.length;
|
|
||||||
return formatNumber(average.toFixed(1));
|
|
||||||
})()}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,50 @@ class ApiService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// POST to external absolute endpoint while reusing token handling
|
||||||
|
public async postAbsolute<T = any>(
|
||||||
|
fullUrl: string,
|
||||||
|
data?: any,
|
||||||
|
): Promise<ApiResponse<T>> {
|
||||||
|
const defaultHeaders: HeadersInit = {
|
||||||
|
"Content-Type": "application/json;charset=UTF-8",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.token) {
|
||||||
|
defaultHeaders.Authorization = `Bearer ${this.token}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const config: RequestInit = {
|
||||||
|
method: "POST",
|
||||||
|
headers: defaultHeaders,
|
||||||
|
body: data ? JSON.stringify(data) : undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(fullUrl, config);
|
||||||
|
const apiData: ApiResponse<T> = await response.json();
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(apiData?.message || `HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof apiData?.state !== "undefined" && apiData.state !== 0) {
|
||||||
|
throw new Error(apiData.message || "API error occurred");
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiData;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("API absolute POST failed:", error);
|
||||||
|
throw error as Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Innovation process function call wrapper
|
||||||
|
public async callInnovationProcess<T = any>(payload: any) {
|
||||||
|
const url = "https://inogen-back.pelekan.org/api/call";
|
||||||
|
return this.postAbsolute<T>(url, payload);
|
||||||
|
}
|
||||||
|
|
||||||
// GET request
|
// GET request
|
||||||
public async get<T = any>(endpoint: string): Promise<ApiResponse<T>> {
|
public async get<T = any>(endpoint: string): Promise<ApiResponse<T>> {
|
||||||
return this.request<T>(endpoint, {
|
return this.request<T>(endpoint, {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user